about summary refs log tree commit diff stats
path: root/src/command
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2013-06-01 23:48:24 +0100
committerJames Booth <boothj5@gmail.com>2013-06-01 23:48:24 +0100
commit518b6721fffa447a05a7af4363be14f69811b4d0 (patch)
treec249d996d50599268d5165f41a6081410b901604 /src/command
parentd49a01a9c37b6aff82cac6a61269a87b3bb211dd (diff)
downloadprofani-tty-518b6721fffa447a05a7af4363be14f69811b4d0.tar.gz
Added /roster add command
Diffstat (limited to 'src/command')
-rw-r--r--src/command/command.c68
1 files changed, 43 insertions, 25 deletions
diff --git a/src/command/command.c b/src/command/command.c
index 6309ad75..7dbf0009 100644
--- a/src/command/command.c
+++ b/src/command/command.c
@@ -2008,6 +2008,13 @@ _cmd_msg(gchar **args, struct cmd_help_t help)
 static gboolean
 _cmd_roster(gchar **args, struct cmd_help_t help)
 {
+    jabber_conn_status_t conn_status = jabber_get_connection_status();
+
+    if (conn_status != JABBER_CONNECTED) {
+        cons_show("You are not currently connected.");
+        return TRUE;
+    }
+
     // show roster
     if (args[0] == NULL) {
         GSList *list = roster_get_contacts();
@@ -2015,41 +2022,52 @@ _cmd_roster(gchar **args, struct cmd_help_t help)
         return TRUE;
     }
 
-    // first arg invalid
-    if (strcmp(args[0], "nick") != 0) {
-        cons_show("Usage: %s", help.usage);
-        return TRUE;
-    }
+    // add contact
+    if (strcmp(args[0], "add") == 0) {
 
-    if (args[1] == NULL) {
-        cons_show("Usage: %s", help.usage);
-        return TRUE;
-    }
+        if (args[1] == NULL) {
+            cons_show("Usage: %s", help.usage);
+            return TRUE;
+        }
 
-    char *jid = args[1];
-    char *name = args[2];
-    jabber_conn_status_t conn_status = jabber_get_connection_status();
+        char *jid = args[1];
+        char *name = args[2];
 
-    if (conn_status != JABBER_CONNECTED) {
-        cons_show("You are not currently connected.");
-        return TRUE;
-    }
+        roster_add_new(jid, name);
 
-    // contact does not exist
-    PContact contact = roster_get_contact(jid);
-    if (contact == NULL) {
-        cons_show("Contact not found in roster: %s", jid);
         return TRUE;
     }
 
-    roster_change_name(jid, name);
+    // change nickname
+    if (strcmp(args[0], "nick") == 0) {
 
-    if (name == NULL) {
-        cons_show("Nickname for %s removed.", jid);
-    } else {
-        cons_show("Nickname for %s set to: %s.", jid, name);
+        if (args[1] == NULL) {
+            cons_show("Usage: %s", help.usage);
+            return TRUE;
+        }
+
+        char *jid = args[1];
+        char *name = args[2];
+
+        // contact does not exist
+        PContact contact = roster_get_contact(jid);
+        if (contact == NULL) {
+            cons_show("Contact not found in roster: %s", jid);
+            return TRUE;
+        }
+
+        roster_change_name(jid, name);
+
+        if (name == NULL) {
+            cons_show("Nickname for %s removed.", jid);
+        } else {
+            cons_show("Nickname for %s set to: %s.", jid, name);
+        }
+
+        return TRUE;
     }
 
+    cons_show("Usage: %s", help.usage);
     return TRUE;
 }