1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-11-03 19:37:16 -05:00

Added /affiliation and /role commands

This commit is contained in:
James Booth 2014-10-12 00:43:58 +01:00
parent c66d03539d
commit 8b1d0bdc3f
5 changed files with 214 additions and 148 deletions

View File

@ -4,3 +4,4 @@ Fix room commands help
Show role/affiliation on join
Show role/affiliation on update
Check all commands from private conversations
Test all freetext args

View File

@ -88,10 +88,11 @@ static char * _alias_autocomplete(char *input, int *size);
static char * _join_autocomplete(char *input, int *size);
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);
static char * _ban_autocomplete(char *input, int *size);
static char * _affiliation_autocomplete(char *input, int *size);
static char * _role_autocomplete(char *input, int *size);
GHashTable *commands = NULL;
@ -347,6 +348,26 @@ static struct cmd_t command_defs[] =
"clear - Clear the room subject.",
NULL } } },
{ "/affiliation",
cmd_affiliation, parse_args, 1, 3, NULL,
{ "/affiliation set|list [affiliation] [jid]", "Manage room affiliations.",
{ "/affiliation set|list [affiliation] [jid]",
"-----------------------------------------",
"set affiliation jid - Set the affiliation of user with jid.",
"list affiliation - List all users with the specified affiliation.",
"The affiliation may be one of owner, admin, member, outcast or none.",
NULL } } },
{ "/role",
cmd_role, parse_args, 1, 3, NULL,
{ "/role set|list [role] [nick]", "Manage room roles.",
{ "/role set|list [role] [nick]",
"----------------------------",
"set role nick - Set the role of occupant with nick.",
"list role - List all occupants with the specified role.",
"The role may be one of moderator, participant, visitor or none.",
NULL } } },
{ "/occupants",
cmd_occupants, parse_args, 1, 2, &cons_occupants_setting,
{ "/occupants show|hide|default [show|hide]", "Show or hide room occupants.",
@ -1013,9 +1034,9 @@ static Autocomplete alias_ac;
static Autocomplete aliases_ac;
static Autocomplete join_property_ac;
static Autocomplete room_ac;
static Autocomplete room_affiliation_ac;
static Autocomplete room_role_ac;
static Autocomplete room_cmd_ac;
static Autocomplete affiliation_ac;
static Autocomplete role_ac;
static Autocomplete privilege_cmd_ac;
static Autocomplete subject_ac;
static Autocomplete form_ac;
static Autocomplete occupants_ac;
@ -1291,25 +1312,23 @@ cmd_init(void)
autocomplete_add(room_ac, "accept");
autocomplete_add(room_ac, "destroy");
autocomplete_add(room_ac, "config");
autocomplete_add(room_ac, "role");
autocomplete_add(room_ac, "affiliation");
room_affiliation_ac = autocomplete_new();
autocomplete_add(room_affiliation_ac, "owner");
autocomplete_add(room_affiliation_ac, "admin");
autocomplete_add(room_affiliation_ac, "member");
autocomplete_add(room_affiliation_ac, "none");
autocomplete_add(room_affiliation_ac, "outcast");
affiliation_ac = autocomplete_new();
autocomplete_add(affiliation_ac, "owner");
autocomplete_add(affiliation_ac, "admin");
autocomplete_add(affiliation_ac, "member");
autocomplete_add(affiliation_ac, "none");
autocomplete_add(affiliation_ac, "outcast");
room_role_ac = autocomplete_new();
autocomplete_add(room_role_ac, "moderator");
autocomplete_add(room_role_ac, "participant");
autocomplete_add(room_role_ac, "visitor");
autocomplete_add(room_role_ac, "none");
role_ac = autocomplete_new();
autocomplete_add(role_ac, "moderator");
autocomplete_add(role_ac, "participant");
autocomplete_add(role_ac, "visitor");
autocomplete_add(role_ac, "none");
room_cmd_ac = autocomplete_new();
autocomplete_add(room_cmd_ac, "list");
autocomplete_add(room_cmd_ac, "set");
privilege_cmd_ac = autocomplete_new();
autocomplete_add(privilege_cmd_ac, "list");
autocomplete_add(privilege_cmd_ac, "set");
subject_ac = autocomplete_new();
autocomplete_add(subject_ac, "set");
@ -1376,9 +1395,9 @@ cmd_uninit(void)
autocomplete_free(aliases_ac);
autocomplete_free(join_property_ac);
autocomplete_free(room_ac);
autocomplete_free(room_affiliation_ac);
autocomplete_free(room_role_ac);
autocomplete_free(room_cmd_ac);
autocomplete_free(affiliation_ac);
autocomplete_free(role_ac);
autocomplete_free(privilege_cmd_ac);
autocomplete_free(subject_ac);
autocomplete_free(form_ac);
autocomplete_free(occupants_ac);
@ -1509,9 +1528,9 @@ cmd_reset_autocomplete()
autocomplete_reset(aliases_ac);
autocomplete_reset(join_property_ac);
autocomplete_reset(room_ac);
autocomplete_reset(room_affiliation_ac);
autocomplete_reset(room_role_ac);
autocomplete_reset(room_cmd_ac);
autocomplete_reset(affiliation_ac);
autocomplete_reset(role_ac);
autocomplete_reset(privilege_cmd_ac);
autocomplete_reset(subject_ac);
autocomplete_reset(form_ac);
autocomplete_reset(occupants_ac);
@ -1773,8 +1792,8 @@ _cmd_complete_parameters(char *input, int *size)
}
}
gchar *cmds[] = { "/help", "/prefs", "/disco", "/close", "/wins", "/subject" };
Autocomplete completers[] = { help_ac, prefs_ac, disco_ac, close_ac, wins_ac, subject_ac };
gchar *cmds[] = { "/help", "/prefs", "/disco", "/close", "/wins", "/subject", "/room" };
Autocomplete completers[] = { help_ac, prefs_ac, disco_ac, close_ac, wins_ac, subject_ac, room_ac };
for (i = 0; i < ARRAY_SIZE(cmds); i++) {
result = autocomplete_param_with_ac(input, size, cmds[i], completers[i], TRUE);
@ -1803,10 +1822,11 @@ _cmd_complete_parameters(char *input, int *size)
g_hash_table_insert(ac_funcs, "/alias", _alias_autocomplete);
g_hash_table_insert(ac_funcs, "/join", _join_autocomplete);
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);
g_hash_table_insert(ac_funcs, "/ban", _ban_autocomplete);
g_hash_table_insert(ac_funcs, "/affiliation", _affiliation_autocomplete);
g_hash_table_insert(ac_funcs, "/role", _role_autocomplete);
char parsed[*size+1];
i = 0;
@ -2382,36 +2402,21 @@ _ban_autocomplete(char *input, int *size)
}
static char *
_room_autocomplete(char *input, int *size)
_affiliation_autocomplete(char *input, int *size)
{
char *result = NULL;
gboolean parse_result;
char *recipient = ui_current_recipient();
Autocomplete nick_ac = muc_roster_ac(recipient);
gboolean parse_result;
Autocomplete jid_ac = muc_roster_jid_ac(recipient);
input[*size] = '\0';
gchar **args = parse_args(input, 4, 4, &parse_result);
gchar **args = parse_args(input, 3, 3, &parse_result);
if ((strncmp(input, "/room role", 10) == 0) && (parse_result == TRUE)) {
GString *beginning = g_string_new("/room role ");
g_string_append(beginning, args[1]);
if ((strncmp(input, "/affiliation", 12) == 0) && (parse_result == TRUE)) {
GString *beginning = g_string_new("/affiliation ");
g_string_append(beginning, args[0]);
g_string_append(beginning, " ");
g_string_append(beginning, args[2]);
result = autocomplete_param_with_ac(input, size, beginning->str, nick_ac, TRUE);
g_string_free(beginning, TRUE);
if (result != NULL) {
return result;
}
}
if ((strncmp(input, "/room affiliation", 17) == 0) && (parse_result == TRUE)) {
GString *beginning = g_string_new("/room affiliation ");
g_string_append(beginning, args[1]);
g_string_append(beginning, " ");
g_string_append(beginning, args[2]);
result = autocomplete_param_with_ac(input, size, beginning->str, jid_ac, TRUE);
g_string_free(beginning, TRUE);
@ -2420,37 +2425,59 @@ _room_autocomplete(char *input, int *size)
}
}
result = autocomplete_param_with_ac(input, size, "/room role set", room_role_ac, TRUE);
result = autocomplete_param_with_ac(input, size, "/affiliation set", affiliation_ac, TRUE);
if (result != NULL) {
return result;
}
result = autocomplete_param_with_ac(input, size, "/room role list", room_role_ac, TRUE);
result = autocomplete_param_with_ac(input, size, "/affiliation list", affiliation_ac, TRUE);
if (result != NULL) {
return result;
}
result = autocomplete_param_with_ac(input, size, "/room affiliation set", room_affiliation_ac, TRUE);
result = autocomplete_param_with_ac(input, size, "/affiliation", privilege_cmd_ac, TRUE);
if (result != NULL) {
return result;
}
result = autocomplete_param_with_ac(input, size, "/room affiliation list", room_affiliation_ac, TRUE);
return NULL;
}
static char *
_role_autocomplete(char *input, int *size)
{
char *result = NULL;
char *recipient = ui_current_recipient();
gboolean parse_result;
Autocomplete nick_ac = muc_roster_ac(recipient);
input[*size] = '\0';
gchar **args = parse_args(input, 3, 3, &parse_result);
if ((strncmp(input, "/role", 5) == 0) && (parse_result == TRUE)) {
GString *beginning = g_string_new("/role ");
g_string_append(beginning, args[0]);
g_string_append(beginning, " ");
g_string_append(beginning, args[1]);
result = autocomplete_param_with_ac(input, size, beginning->str, nick_ac, TRUE);
g_string_free(beginning, TRUE);
if (result != NULL) {
return result;
}
}
result = autocomplete_param_with_ac(input, size, "/role set", role_ac, TRUE);
if (result != NULL) {
return result;
}
result = autocomplete_param_with_ac(input, size, "/room affiliation", room_cmd_ac, TRUE);
result = autocomplete_param_with_ac(input, size, "/role list", role_ac, TRUE);
if (result != NULL) {
return result;
}
result = autocomplete_param_with_ac(input, size, "/room role", room_cmd_ac, TRUE);
if (result != NULL) {
return result;
}
result = autocomplete_param_with_ac(input, size, "/room", room_ac, TRUE);
result = autocomplete_param_with_ac(input, size, "/role", privilege_cmd_ac, TRUE);
if (result != NULL) {
return result;
}

View File

@ -2222,6 +2222,125 @@ cmd_subject(gchar **args, struct cmd_help_t help)
return TRUE;
}
gboolean
cmd_affiliation(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 '/affiliation' does not apply to this window.");
return TRUE;
}
char *cmd = args[0];
if (cmd == NULL) {
cons_show("Usage: %s", help.usage);
return TRUE;
}
char *affiliation = args[1];
if ((g_strcmp0(affiliation, "owner") != 0) &&
(g_strcmp0(affiliation, "admin") != 0) &&
(g_strcmp0(affiliation, "member") != 0) &&
(g_strcmp0(affiliation, "none") != 0) &&
(g_strcmp0(affiliation, "outcast") != 0)) {
cons_show("Usage: %s", help.usage);
return TRUE;
}
char *room = ui_current_recipient();
ProfWin *window = wins_get_by_recipient(room);
if (g_strcmp0(cmd, "list") == 0) {
if (g_strcmp0(affiliation, "none") == 0) {
win_save_print(window, '!', NULL, 0, 0, "", "Cannot list users with no affiliation.");
} else {
iq_room_affiliation_list(room, affiliation);
}
return TRUE;
}
if (g_strcmp0(cmd, "set") == 0) {
char *jid = args[2];
if (jid == NULL) {
cons_show("Usage: %s", help.usage);
return TRUE;
} else {
char *reason = args[3];
iq_room_affiliation_set(room, jid, affiliation, reason);
return TRUE;
}
}
return TRUE;
}
gboolean
cmd_role(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 '/role' does not apply to this window.");
return TRUE;
}
char *cmd = args[0];
if (cmd == NULL) {
cons_show("Usage: %s", help.usage);
return TRUE;
}
char *role = args[1];
if ((g_strcmp0(role, "visitor") != 0) &&
(g_strcmp0(role, "participant") != 0) &&
(g_strcmp0(role, "moderator") != 0) &&
(g_strcmp0(role, "none") != 0)) {
cons_show("Usage: %s", help.usage);
return TRUE;
}
char *room = ui_current_recipient();
ProfWin *window = wins_get_by_recipient(room);
if (g_strcmp0(cmd, "list") == 0) {
if (g_strcmp0(role, "none") == 0) {
win_save_print(window, '!', NULL, 0, 0, "", "Cannot list users with no role.");
} else if (g_strcmp0(role, "visitor") == 0) {
win_save_print(window, '!', NULL, 0, 0, "", "Cannot list users with visitor role.");
} else {
iq_room_role_list(room, role);
}
return TRUE;
}
if (g_strcmp0(cmd, "set") == 0) {
char *nick = args[2];
if (nick == NULL) {
cons_show("Usage: %s", help.usage);
return TRUE;
} else {
char *reason = args[3];
iq_room_role_set(room, nick, role, reason);
return TRUE;
}
}
return TRUE;
}
gboolean
cmd_room(gchar **args, struct cmd_help_t help)
{
@ -2240,9 +2359,7 @@ cmd_room(gchar **args, struct cmd_help_t help)
if ((g_strcmp0(args[0], "accept") != 0) &&
(g_strcmp0(args[0], "destroy") != 0) &&
(g_strcmp0(args[0], "config") != 0) &&
(g_strcmp0(args[0], "role") != 0) &&
(g_strcmp0(args[0], "affiliation") != 0)) {
(g_strcmp0(args[0], "config") != 0)) {
cons_show("Usage: %s", help.usage);
return TRUE;
}
@ -2256,89 +2373,6 @@ cmd_room(gchar **args, struct cmd_help_t help)
ui_index = 0;
}
if (g_strcmp0(args[0], "affiliation") == 0) {
char *cmd = args[1];
if (cmd == NULL) {
cons_show("Usage: %s", help.usage);
return TRUE;
}
char *affiliation = args[2];
if ((g_strcmp0(affiliation, "owner") != 0) &&
(g_strcmp0(affiliation, "admin") != 0) &&
(g_strcmp0(affiliation, "member") != 0) &&
(g_strcmp0(affiliation, "none") != 0) &&
(g_strcmp0(affiliation, "outcast") != 0)) {
cons_show("Usage: %s", help.usage);
return TRUE;
}
if (g_strcmp0(cmd, "list") == 0) {
if (g_strcmp0(affiliation, "none") == 0) {
win_save_print(window, '!', NULL, 0, 0, "", "Cannot list users with no affiliation.");
} else {
iq_room_affiliation_list(room, affiliation);
}
return TRUE;
}
if (g_strcmp0(cmd, "set") == 0) {
char *jid = args[3];
if (jid == NULL) {
cons_show("Usage: %s", help.usage);
return TRUE;
} else {
char *reason = args[4];
iq_room_affiliation_set(room, jid, affiliation, reason);
return TRUE;
}
}
return TRUE;
}
if (g_strcmp0(args[0], "role") == 0) {
char *cmd = args[1];
if (cmd == NULL) {
cons_show("Usage: %s", help.usage);
return TRUE;
}
char *role = args[2];
if ((g_strcmp0(role, "visitor") != 0) &&
(g_strcmp0(role, "participant") != 0) &&
(g_strcmp0(role, "moderator") != 0) &&
(g_strcmp0(role, "none") != 0)) {
cons_show("Usage: %s", help.usage);
return TRUE;
}
if (g_strcmp0(cmd, "list") == 0) {
if (g_strcmp0(role, "none") == 0) {
win_save_print(window, '!', NULL, 0, 0, "", "Cannot list users with no role.");
} else if (g_strcmp0(role, "visitor") == 0) {
win_save_print(window, '!', NULL, 0, 0, "", "Cannot list users with visitor role.");
} else {
iq_room_role_list(room, role);
}
return TRUE;
}
if (g_strcmp0(cmd, "set") == 0) {
char *nick = args[3];
if (nick == NULL) {
cons_show("Usage: %s", help.usage);
return TRUE;
} else {
char *reason = args[4];
iq_room_role_set(room, nick, role, reason);
return TRUE;
}
}
return TRUE;
}
if (g_strcmp0(args[0], "accept") == 0) {
gboolean requires_config = muc_requires_config(room);
if (!requires_config) {

View File

@ -130,5 +130,7 @@ 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);
gboolean cmd_subject(gchar **args, struct cmd_help_t help);
gboolean cmd_affiliation(gchar **args, struct cmd_help_t help);
gboolean cmd_role(gchar **args, struct cmd_help_t help);
#endif

View File

@ -762,6 +762,8 @@ handle_muc_occupant_online(const char * const room, const char * const nick, con
}
prefs_free_string(muc_status_pref);
ui_muc_roster(room);
} else {
ui_muc_roster(room);
}
}