diff options
-rw-r--r-- | doc/user-guide/commands.xml | 63 | ||||
-rw-r--r-- | root_commands.c | 257 |
2 files changed, 118 insertions, 202 deletions
diff --git a/doc/user-guide/commands.xml b/doc/user-guide/commands.xml index 96d54530..edf89d46 100644 --- a/doc/user-guide/commands.xml +++ b/doc/user-guide/commands.xml @@ -5,7 +5,7 @@ <bitlbee-command name="account"> <short-description>IM-account list maintenance</short-description> - <syntax>account <action> [<arguments>]</syntax> + <syntax>account [<account id>] <action> [<arguments>]</syntax> <description> @@ -98,7 +98,7 @@ </bitlbee-command> <bitlbee-command name="del"> - <syntax>account del <account id></syntax> + <syntax>account <account id> del</syntax> <description> <para> @@ -113,7 +113,7 @@ </bitlbee-command> <bitlbee-command name="on"> - <syntax>account on [<account id>]</syntax> + <syntax>account [<account id>] on</syntax> <description> <para> @@ -128,7 +128,7 @@ </bitlbee-command> <bitlbee-command name="off"> - <syntax>account off [<account id>]</syntax> + <syntax>account [<account id>] off</syntax> <description> <para> @@ -152,10 +152,10 @@ </bitlbee-command> <bitlbee-command name="set"> - <syntax>account set <account id></syntax> - <syntax>account set <account id>/<setting></syntax> - <syntax>account set <account id>/<setting> <value></syntax> - <syntax>account set -del <account id>/<setting></syntax> + <syntax>account <account id> set</syntax> + <syntax>account <account id> set <setting></syntax> + <syntax>account <account id> set <setting> <value></syntax> + <syntax>account <account id> set -del <setting></syntax> <description> <para> @@ -180,7 +180,7 @@ <description> <para> - Available actions: add, del, list, with and set. See <emphasis>help chat <action></emphasis> for more information. + Available actions: add, with. See <emphasis>help chat <action></emphasis> for more information. </para> </description> @@ -204,30 +204,6 @@ </bitlbee-command> - <bitlbee-command name="del"> - <syntax>chat del <chat id></syntax> - - <description> - <para> - This commands deletes an chatroom from your list. - </para> - - <para> - The room ID can be a number (see <emphasis>chat list</emphasis>), or (part of) the name of the room/channel. - </para> - </description> - </bitlbee-command> - - <bitlbee-command name="list"> - <syntax>chat list</syntax> - - <description> - <para> - This command gives you a list of all the chatrooms known by BitlBee. - </para> - </description> - </bitlbee-command> - <bitlbee-command name="with"> <syntax>chat with <nickname></syntax> @@ -237,27 +213,6 @@ </para> </description> </bitlbee-command> - - <bitlbee-command name="set"> - <syntax>chat set <chat id></syntax> - <syntax>chat set <chat id>/<setting></syntax> - <syntax>chat set <chat id>/<setting> <value></syntax> - <syntax>chat set -del <chat id>/<setting></syntax> - - <description> - <para> - This command can be used to change various settings for chatrooms. - </para> - - <para> - For more infomation about a setting, see <emphasis>help set <setting></emphasis>. - </para> - - <para> - The room ID can be a number (see <emphasis>chat list</emphasis>), or (part of) the name of the room/channel. - </para> - </description> - </bitlbee-command> </bitlbee-command> <bitlbee-command name="add"> diff --git a/root_commands.c b/root_commands.c index ea110467..63f1c867 100644 --- a/root_commands.c +++ b/root_commands.c @@ -240,49 +240,24 @@ static void cmd_showset( irc_t *irc, set_t **head, char *key ) typedef set_t** (*cmd_set_findhead)( irc_t*, char* ); typedef int (*cmd_set_checkflags)( irc_t*, set_t *set ); -static int cmd_set_real( irc_t *irc, char **cmd, cmd_set_findhead findhead, cmd_set_checkflags checkflags ) +static int cmd_set_real( irc_t *irc, char **cmd, set_t **head, cmd_set_checkflags checkflags ) { - char *set_full = NULL, *set_name = NULL, *tmp; - set_t **head; + char *set_name = NULL, *value = NULL; + gboolean del = FALSE; if( cmd[1] && g_strncasecmp( cmd[1], "-del", 4 ) == 0 ) { MIN_ARGS( 2, 0 ); - set_full = cmd[2]; + set_name = cmd[2]; + del = TRUE; } else - set_full = cmd[1]; - - if( findhead == NULL ) - { - set_name = set_full; - - head = &irc->b->set; - } - else { - char *id; - - if( ( tmp = strchr( set_full, '/' ) ) ) - { - id = g_strndup( set_full, ( tmp - set_full ) ); - set_name = tmp + 1; - } - else - { - id = g_strdup( set_full ); - } - - if( ( head = findhead( irc, id ) ) == NULL ) - { - g_free( id ); - irc_usermsg( irc, "Could not find setting." ); - return 0; - } - g_free( id ); + set_name = cmd[1]; + value = cmd[2]; } - if( cmd[1] && cmd[2] && set_name ) + if( set_name && ( value || del ) ) { set_t *s = set_find( head, set_name ); int st; @@ -290,13 +265,16 @@ static int cmd_set_real( irc_t *irc, char **cmd, cmd_set_findhead findhead, cmd_ if( s && checkflags && checkflags( irc, s ) == 0 ) return 0; - if( g_strncasecmp( cmd[1], "-del", 4 ) == 0 ) + if( del ) st = set_reset( head, set_name ); else - st = set_setstr( head, set_name, cmd[2] ); + st = set_setstr( head, set_name, value ); if( set_getstr( head, set_name ) == NULL ) { + /* This happens when changing the passwd, for example. + Showing these msgs instead gives slightly clearer + feedback. */ if( st ) irc_usermsg( irc, "Setting changed successfully" ); else @@ -324,16 +302,6 @@ static int cmd_set_real( irc_t *irc, char **cmd, cmd_set_findhead findhead, cmd_ return 1; } -static set_t **cmd_account_set_findhead( irc_t *irc, char *id ) -{ - account_t *a; - - if( ( a = account_get( irc->b, id ) ) ) - return &a->set; - else - return NULL; -} - static int cmd_account_set_checkflags( irc_t *irc, set_t *s ) { account_t *a = s->data; @@ -385,24 +353,8 @@ static void cmd_account( irc_t *irc, char **cmd ) } irc_usermsg( irc, "Account successfully added" ); - } - else if( g_strcasecmp( cmd[1], "del" ) == 0 ) - { - MIN_ARGS( 2 ); - - if( !( a = account_get( irc->b, cmd[2] ) ) ) - { - irc_usermsg( irc, "Invalid account" ); - } - else if( a->ic ) - { - irc_usermsg( irc, "Account is still logged in, can't delete" ); - } - else - { - account_del( irc->b, a ); - irc_usermsg( irc, "Account deleted" ); - } + + return; } else if( g_strcasecmp( cmd[1], "list" ) == 0 ) { @@ -429,113 +381,112 @@ static void cmd_account( irc_t *irc, char **cmd ) i ++; } irc_usermsg( irc, "End of account list" ); + + return; + } + else if( cmd[2] ) + { + /* Try the following two only if cmd[2] == NULL */ } else if( g_strcasecmp( cmd[1], "on" ) == 0 ) { - if( cmd[2] ) + if ( irc->b->accounts ) { - if( ( a = account_get( irc->b, cmd[2] ) ) ) - { - if( a->ic ) - { - irc_usermsg( irc, "Account already online" ); - return; - } - else - { + irc_usermsg( irc, "Trying to get all accounts connected..." ); + + for( a = irc->b->accounts; a; a = a->next ) + if( !a->ic && a->auto_connect ) account_on( irc->b, a ); - } - } - else - { - irc_usermsg( irc, "Invalid account" ); - return; - } - } + } else { - if ( irc->b->accounts ) - { - irc_usermsg( irc, "Trying to get all accounts connected..." ); - - for( a = irc->b->accounts; a; a = a->next ) - if( !a->ic && a->auto_connect ) - account_on( irc->b, a ); - } - else - { - irc_usermsg( irc, "No accounts known. Use `account add' to add one." ); - } + irc_usermsg( irc, "No accounts known. Use `account add' to add one." ); } + + return; } else if( g_strcasecmp( cmd[1], "off" ) == 0 ) { - if( !cmd[2] ) - { - irc_usermsg( irc, "Deactivating all active (re)connections..." ); - - for( a = irc->b->accounts; a; a = a->next ) - { - if( a->ic ) - account_off( irc->b, a ); - else if( a->reconnect ) - cancel_auto_reconnect( a ); - } - } - else if( ( a = account_get( irc->b, cmd[2] ) ) ) + irc_usermsg( irc, "Deactivating all active (re)connections..." ); + + for( a = irc->b->accounts; a; a = a->next ) { if( a->ic ) - { account_off( irc->b, a ); - } else if( a->reconnect ) - { cancel_auto_reconnect( a ); - irc_usermsg( irc, "Reconnect cancelled" ); - } - else - { - irc_usermsg( irc, "Account already offline" ); - return; - } + } + + return; + } + + MIN_ARGS( 2 ); + + /* At least right now, don't accept on/off/set/del as account IDs even + if they're a proper match, since people not familiar with the new + syntax yet may get a confusing/nasty surprise. */ + if( g_strcasecmp( cmd[1], "on" ) == 0 || + g_strcasecmp( cmd[1], "off" ) == 0 || + g_strcasecmp( cmd[1], "set" ) == 0 || + g_strcasecmp( cmd[1], "del" ) == 0 || + ( a = account_get( irc->b, cmd[1] ) ) == NULL ) + { + irc_usermsg( irc, "Could not find account `%s'. Note that the syntax " + "of the account command changed, see \x02help account\x02.", cmd[1] ); + + return; + } + + if( g_strcasecmp( cmd[2], "del" ) == 0 ) + { + if( a->ic ) + { + irc_usermsg( irc, "Account is still logged in, can't delete" ); } else { - irc_usermsg( irc, "Invalid account" ); - return; + account_del( irc->b, a ); + irc_usermsg( irc, "Account deleted" ); } } - else if( g_strcasecmp( cmd[1], "set" ) == 0 ) + else if( g_strcasecmp( cmd[2], "on" ) == 0 ) { - MIN_ARGS( 2 ); - - cmd_set_real( irc, cmd + 1, cmd_account_set_findhead, cmd_account_set_checkflags ); + if( a->ic ) + irc_usermsg( irc, "Account already online" ); + else + account_on( irc->b, a ); + } + else if( g_strcasecmp( cmd[2], "off" ) == 0 ) + { + if( a->ic ) + { + account_off( irc->b, a ); + } + else if( a->reconnect ) + { + cancel_auto_reconnect( a ); + irc_usermsg( irc, "Reconnect cancelled" ); + } + else + { + irc_usermsg( irc, "Account already offline" ); + } + } + else if( g_strcasecmp( cmd[2], "set" ) == 0 ) + { + cmd_set_real( irc, cmd + 2, &a->set, cmd_account_set_checkflags ); } else { - irc_usermsg( irc, "Unknown command: %s %s. Please use \x02help commands\x02 to get a list of available commands.", "account", cmd[1] ); + irc_usermsg( irc, "Unknown command: %s [...] %s. Please use \x02help commands\x02 to get a list of available commands.", "account", cmd[2] ); } } -static set_t **cmd_channel_set_findhead( irc_t *irc, char *id ) +static void cmd_channel( irc_t *irc, char **cmd ) { irc_channel_t *ic; - if( ( ic = irc_channel_get( irc, id ) ) ) - return &ic->set; - else - return NULL; -} - -static void cmd_channel( irc_t *irc, char **cmd ) -{ - if( g_strcasecmp( cmd[1], "set" ) == 0 ) - { - MIN_ARGS( 2 ); - - cmd_set_real( irc, cmd + 1, cmd_channel_set_findhead, NULL ); - } - else if( g_strcasecmp( cmd[1], "list" ) == 0 ) + if( g_strcasecmp( cmd[1], "list" ) == 0 ) { GSList *l; int i = 0; @@ -554,15 +505,25 @@ static void cmd_channel( irc_t *irc, char **cmd ) i ++; } irc_usermsg( irc, "End of channel list" ); + + return; } - else if( g_strcasecmp( cmd[1], "del" ) == 0 ) + + MIN_ARGS( 2 ); + + if( ( ic = irc_channel_get( irc, cmd[1] ) ) == NULL ) { - irc_channel_t *ic; - - MIN_ARGS( 2 ); - - if( ( ic = irc_channel_get( irc, cmd[2] ) ) && - !( ic->flags & IRC_CHANNEL_JOINED ) && + irc_usermsg( irc, "Could not find channel `%s'", cmd[1] ); + return; + } + + if( g_strcasecmp( cmd[2], "set" ) == 0 ) + { + cmd_set_real( irc, cmd + 2, &ic->set, NULL ); + } + else if( g_strcasecmp( cmd[2], "del" ) == 0 ) + { + if( !( ic->flags & IRC_CHANNEL_JOINED ) && ic != ic->irc->default_channel ) { irc_usermsg( irc, "Channel %s deleted.", ic->name ); @@ -575,7 +536,7 @@ static void cmd_channel( irc_t *irc, char **cmd ) } else { - irc_usermsg( irc, "Unknown command: %s %s. Please use \x02help commands\x02 to get a list of available commands.", "channel", cmd[1] ); + irc_usermsg( irc, "Unknown command: %s [...] %s. Please use \x02help commands\x02 to get a list of available commands.", "channel", cmd[1] ); } } @@ -911,7 +872,7 @@ static void cmd_yesno( irc_t *irc, char **cmd ) static void cmd_set( irc_t *irc, char **cmd ) { - cmd_set_real( irc, cmd, NULL, NULL ); + cmd_set_real( irc, cmd, &irc->b->set, NULL ); } static void cmd_blist( irc_t *irc, char **cmd ) |