about summary refs log tree commit diff stats
path: root/src/command
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2013-02-17 01:04:10 +0000
committerJames Booth <boothj5@gmail.com>2013-02-17 01:04:10 +0000
commit44d2f8da7a235997049bac68fea746682ae49e9f (patch)
tree084d2440cdb88815e532e5e6c526d04611bde8a0 /src/command
parentab591b41b2535f454d35d7524c454dccea1b2cc5 (diff)
downloadprofani-tty-44d2f8da7a235997049bac68fea746682ae49e9f.tar.gz
Added /caps command
Diffstat (limited to 'src/command')
-rw-r--r--src/command/command.c78
1 files changed, 78 insertions, 0 deletions
diff --git a/src/command/command.c b/src/command/command.c
index 648ab64c..58868334 100644
--- a/src/command/command.c
+++ b/src/command/command.c
@@ -125,6 +125,7 @@ static gboolean _cmd_dnd(gchar **args, struct cmd_help_t help);
 static gboolean _cmd_chat(gchar **args, struct cmd_help_t help);
 static gboolean _cmd_xa(gchar **args, struct cmd_help_t help);
 static gboolean _cmd_info(gchar **args, struct cmd_help_t help);
+static gboolean _cmd_caps(gchar **args, struct cmd_help_t help);
 static gboolean _cmd_wins(gchar **args, struct cmd_help_t help);
 static gboolean _cmd_nick(gchar **args, struct cmd_help_t help);
 static gboolean _cmd_theme(gchar **args, struct cmd_help_t help);
@@ -268,6 +269,16 @@ static struct cmd_t main_commands[] =
           "If in a chat window the parameter is not required, the current recipient will be used.",
           NULL } } },
 
+    { "/caps",
+        _cmd_caps, parse_args, 0, 1,
+        { "/caps [jid|nick]", "Find out a contacts client capabilities.",
+        { "/caps [jid|nick]",
+          "----------------",
+          "Find out a contact, or room members client capabilities.",
+          "If in a chat window the parameter is not required, the current recipient will be used.",
+          "The command output is similar to the /info command, but shows the capabilities of each available resource.",
+          NULL } } },
+
     { "/status",
         _cmd_status, parse_args, 0, 1,
         { "/status [jid|nick]", "Find out a contacts presence information.",
@@ -964,6 +975,7 @@ _cmd_complete_parameters(char *input, int *size)
         if (nick_ac != NULL) {
             _parameter_autocomplete_with_ac(input, size, "/msg", nick_ac);
             _parameter_autocomplete_with_ac(input, size, "/info", nick_ac);
+            _parameter_autocomplete_with_ac(input, size, "/caps", nick_ac);
             _parameter_autocomplete_with_ac(input, size, "/status", nick_ac);
         }
     } else {
@@ -971,6 +983,8 @@ _cmd_complete_parameters(char *input, int *size)
             contact_list_find_contact);
         _parameter_autocomplete(input, size, "/info",
             contact_list_find_contact);
+        _parameter_autocomplete(input, size, "/caps",
+            contact_list_find_contact);
         _parameter_autocomplete(input, size, "/status",
             contact_list_find_contact);
     }
@@ -1861,6 +1875,70 @@ _cmd_info(gchar **args, struct cmd_help_t help)
 }
 
 static gboolean
+_cmd_caps(gchar **args, struct cmd_help_t help)
+{
+    char *usr = args[0];
+
+    jabber_conn_status_t conn_status = jabber_get_connection_status();
+
+    if (conn_status != JABBER_CONNECTED) {
+        cons_show("You are not currently connected.");
+    } else {
+        if (win_current_is_groupchat()) {
+            if (usr != NULL) {
+                PContact pcontact = muc_get_participant(win_current_get_recipient(), usr);
+                if (pcontact != NULL) {
+                    cons_show_caps(pcontact);
+                } else {
+                    cons_show("No such participant \"%s\" in room.", usr);
+                }
+            } else {
+                cons_show("No nickname supplied to /info in chat room.");
+            }
+
+        } else if (win_current_is_chat()) {
+            if (usr != NULL) {
+                cons_show("No parameter required for /info in chat.");
+            } else {
+                PContact pcontact = contact_list_get_contact(win_current_get_recipient());
+                if (pcontact != NULL) {
+                    cons_show_caps(pcontact);
+                } else {
+                    cons_show("No such contact \"%s\" in roster.", win_current_get_recipient());
+                }
+            }
+
+        } else if (win_current_is_private()) {
+            if (usr != NULL) {
+                win_current_show("No parameter required when in chat.");
+            } else {
+                Jid *jid = jid_create(win_current_get_recipient());
+                PContact pcontact = muc_get_participant(jid->barejid, jid->resourcepart);
+                if (pcontact != NULL) {
+                    cons_show_caps(pcontact);
+                } else {
+                    cons_show("No such participant \"%s\" in room.", jid->resourcepart);
+                }
+                jid_destroy(jid);
+            }
+        } else {
+            if (usr != NULL) {
+                PContact pcontact = contact_list_get_contact(usr);
+                if (pcontact != NULL) {
+                    cons_show_caps(pcontact);
+                } else {
+                    cons_show("No such contact \"%s\" in roster.", usr);
+                }
+            } else {
+                cons_show("Usage: %s", help.usage);
+            }
+        }
+    }
+
+    return TRUE;
+}
+
+static gboolean
 _cmd_join(gchar **args, struct cmd_help_t help)
 {
     jabber_conn_status_t conn_status = jabber_get_connection_status();