From 905442714480a0e3ddb6e555404dbb39481422e7 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sat, 11 Oct 2014 22:43:54 +0100 Subject: [PATCH] Moved /room ban to /ban --- src/command/command.c | 36 ++++++++++++++++++++++++++++-------- src/command/commands.c | 40 ++++++++++++++++++++++++++++------------ src/command/commands.h | 1 + 3 files changed, 57 insertions(+), 20 deletions(-) diff --git a/src/command/command.c b/src/command/command.c index f1e51e2b..de87390a 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -91,6 +91,7 @@ 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); +static char * _ban_autocomplete(char *input, int *size); GHashTable *commands = NULL; @@ -328,6 +329,15 @@ static struct cmd_t command_defs[] = "reason - Optional reason for kicking the occupant.", NULL } } }, + { "/ban", + cmd_ban, parse_args, 1, 2, NULL, + { "/ban jid [reason]", "Ban users from chat rooms.", + { "/ban jid [reason]", + "-----------------", + "jid - Bare JID of the user to ban from the room.", + "reason - Optional reason for banning the user.", + NULL } } }, + { "/occupants", cmd_occupants, parse_args, 1, 2, &cons_occupants_setting, { "/occupants show|hide|default [show|hide]", "Show or hide room occupants.", @@ -1274,7 +1284,6 @@ cmd_init(void) autocomplete_add(room_ac, "config"); autocomplete_add(room_ac, "info"); autocomplete_add(room_ac, "subject"); - autocomplete_add(room_ac, "ban"); autocomplete_add(room_ac, "role"); autocomplete_add(room_ac, "affiliation"); @@ -1790,6 +1799,7 @@ _cmd_complete_parameters(char *input, int *size) 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); + g_hash_table_insert(ac_funcs, "/ban", _ban_autocomplete); char parsed[*size+1]; i = 0; @@ -2347,6 +2357,23 @@ _kick_autocomplete(char *input, int *size) return NULL; } +static char * +_ban_autocomplete(char *input, int *size) +{ + char *result = NULL; + char *recipient = ui_current_recipient(); + Autocomplete jid_ac = muc_roster_jid_ac(recipient); + + if (jid_ac != NULL) { + result = autocomplete_param_with_ac(input, size, "/ban", jid_ac, TRUE); + if (result != NULL) { + return result; + } + } + + return NULL; +} + static char * _room_autocomplete(char *input, int *size) { @@ -2421,13 +2448,6 @@ _room_autocomplete(char *input, int *size) return result; } - if (jid_ac != NULL) { - result = autocomplete_param_with_ac(input, size, "/room ban", jid_ac, TRUE); - if (result != NULL) { - return result; - } - } - result = autocomplete_param_with_ac(input, size, "/room", room_ac, TRUE); if (result != NULL) { return result; diff --git a/src/command/commands.c b/src/command/commands.c index a50a778b..9f62647e 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -2141,6 +2141,34 @@ cmd_kick(gchar **args, struct cmd_help_t help) return TRUE; } +gboolean +cmd_ban(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(); + + char *jid = args[0]; + if (jid) { + char *reason = args[1]; + iq_room_affiliation_set(room, jid, "outcast", reason); + } else { + cons_show("Usage: %s", help.usage); + } + return TRUE; +} + gboolean cmd_room(gchar **args, struct cmd_help_t help) { @@ -2161,7 +2189,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], "ban") != 0) && (g_strcmp0(args[0], "role") != 0) && (g_strcmp0(args[0], "affiliation") != 0) && (g_strcmp0(args[0], "info") != 0)) { @@ -2214,17 +2241,6 @@ cmd_room(gchar **args, struct cmd_help_t help) return TRUE; } - if (g_strcmp0(args[0], "ban") == 0) { - char *jid = args[1]; - if (jid) { - char *reason = args[2]; - iq_room_affiliation_set(room, jid, "outcast", reason); - } else { - cons_show("Usage: %s", help.usage); - } - return TRUE; - } - if (g_strcmp0(args[0], "affiliation") == 0) { char *cmd = args[1]; if (cmd == NULL) { diff --git a/src/command/commands.h b/src/command/commands.h index d53223e0..d6a0254c 100644 --- a/src/command/commands.h +++ b/src/command/commands.h @@ -128,5 +128,6 @@ 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); +gboolean cmd_ban(gchar **args, struct cmd_help_t help); #endif