diff options
author | James Booth <boothj5@gmail.com> | 2014-10-10 13:35:50 +0100 |
---|---|---|
committer | James Booth <boothj5@gmail.com> | 2014-10-10 13:35:50 +0100 |
commit | 02a4beb6febefa60fb1948a1b173d48793944f59 (patch) | |
tree | 14e0dcf1591389c7e4a0d9b1a38f567e8a0a2539 /src/command | |
parent | 6a2bc79ca6a241982a95b64f4941aceea613366b (diff) | |
download | profani-tty-02a4beb6febefa60fb1948a1b173d48793944f59.tar.gz |
Moved /room kick to /kick
Diffstat (limited to 'src/command')
-rw-r--r-- | src/command/command.c | 36 | ||||
-rw-r--r-- | src/command/commands.c | 50 | ||||
-rw-r--r-- | src/command/commands.h | 1 |
3 files changed, 63 insertions, 24 deletions
diff --git a/src/command/command.c b/src/command/command.c index fe0c4adf..f1e51e2b 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -90,6 +90,7 @@ static char * _log_autocomplete(char *input, int *size); static char * _form_autocomplete(char *input, int *size); static char * _room_autocomplete(char *input, int *size); static char * _occupants_autocomplete(char *input, int *size); +static char * _kick_autocomplete(char *input, int *size); GHashTable *commands = NULL; @@ -318,6 +319,15 @@ static struct cmd_t command_defs[] = "info - Show room details.", NULL } } }, + { "/kick", + cmd_kick, parse_args_with_freetext, 1, 2, NULL, + { "/kick nick [reason]", "Kick occupants from chat rooms.", + { "/kick nick [reason]", + "-------------------", + "nick - Nickname of the occupant to kick from the room.", + "reason - Optional reason for kicking the occupant.", + NULL } } }, + { "/occupants", cmd_occupants, parse_args, 1, 2, &cons_occupants_setting, { "/occupants show|hide|default [show|hide]", "Show or hide room occupants.", @@ -1264,7 +1274,6 @@ cmd_init(void) autocomplete_add(room_ac, "config"); autocomplete_add(room_ac, "info"); autocomplete_add(room_ac, "subject"); - autocomplete_add(room_ac, "kick"); autocomplete_add(room_ac, "ban"); autocomplete_add(room_ac, "role"); autocomplete_add(room_ac, "affiliation"); @@ -1780,6 +1789,7 @@ _cmd_complete_parameters(char *input, int *size) g_hash_table_insert(ac_funcs, "/form", _form_autocomplete); g_hash_table_insert(ac_funcs, "/room", _room_autocomplete); g_hash_table_insert(ac_funcs, "/occupants", _occupants_autocomplete); + g_hash_table_insert(ac_funcs, "/kick", _kick_autocomplete); char parsed[*size+1]; i = 0; @@ -2321,6 +2331,23 @@ _occupants_autocomplete(char *input, int *size) } static char * +_kick_autocomplete(char *input, int *size) +{ + char *result = NULL; + char *recipient = ui_current_recipient(); + Autocomplete nick_ac = muc_roster_ac(recipient); + + if (nick_ac != NULL) { + result = autocomplete_param_with_ac(input, size, "/kick", nick_ac, TRUE); + if (result != NULL) { + return result; + } + } + + return NULL; +} + +static char * _room_autocomplete(char *input, int *size) { char *result = NULL; @@ -2394,13 +2421,6 @@ _room_autocomplete(char *input, int *size) return result; } - if (nick_ac != NULL) { - result = autocomplete_param_with_ac(input, size, "/room kick", nick_ac, TRUE); - if (result != NULL) { - return result; - } - } - if (jid_ac != NULL) { result = autocomplete_param_with_ac(input, size, "/room ban", jid_ac, TRUE); if (result != NULL) { diff --git a/src/command/commands.c b/src/command/commands.c index 2309b008..a50a778b 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -2108,6 +2108,40 @@ cmd_form(gchar **args, struct cmd_help_t help) } gboolean +cmd_kick(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; + } + + win_type_t win_type = ui_current_win_type(); + if (win_type != WIN_MUC) { + cons_show("Command '/kick' only applies in chat rooms."); + return TRUE; + } + + char *room = ui_current_recipient(); + ProfWin *window = wins_get_by_recipient(room); + + char *nick = args[0]; + if (nick) { + if (muc_roster_contains_nick(room, nick)) { + char *reason = args[1]; + iq_room_kick_occupant(room, nick, reason); + } else { + win_save_vprint(window, '!', NULL, 0, 0, "", "Occupant does not exist: %s", nick); + } + } else { + cons_show("Usage: %s", help.usage); + } + + return TRUE; +} + +gboolean cmd_room(gchar **args, struct cmd_help_t help) { jabber_conn_status_t conn_status = jabber_get_connection_status(); @@ -2127,7 +2161,6 @@ cmd_room(gchar **args, struct cmd_help_t help) (g_strcmp0(args[0], "destroy") != 0) && (g_strcmp0(args[0], "config") != 0) && (g_strcmp0(args[0], "subject") != 0) && - (g_strcmp0(args[0], "kick") != 0) && (g_strcmp0(args[0], "ban") != 0) && (g_strcmp0(args[0], "role") != 0) && (g_strcmp0(args[0], "affiliation") != 0) && @@ -2181,21 +2214,6 @@ cmd_room(gchar **args, struct cmd_help_t help) return TRUE; } - if (g_strcmp0(args[0], "kick") == 0) { - char *nick = args[1]; - if (nick) { - if (muc_roster_contains_nick(room, nick)) { - char *reason = args[2]; - iq_room_kick_occupant(room, nick, reason); - } else { - win_save_vprint(window, '!', NULL, 0, 0, "", "Occupant does not exist: %s", nick); - } - } else { - cons_show("Usage: %s", help.usage); - } - return TRUE; - } - if (g_strcmp0(args[0], "ban") == 0) { char *jid = args[1]; if (jid) { diff --git a/src/command/commands.h b/src/command/commands.h index 0145cfd8..d53223e0 100644 --- a/src/command/commands.h +++ b/src/command/commands.h @@ -127,5 +127,6 @@ gboolean cmd_xmlconsole(gchar **args, struct cmd_help_t help); gboolean cmd_ping(gchar **args, struct cmd_help_t help); gboolean cmd_form(gchar **args, struct cmd_help_t help); gboolean cmd_occupants(gchar **args, struct cmd_help_t help); +gboolean cmd_kick(gchar **args, struct cmd_help_t help); #endif |