aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--irc.h1
-rw-r--r--irc_channel.c44
-rw-r--r--root_commands.c22
3 files changed, 64 insertions, 3 deletions
diff --git a/irc.h b/irc.h
index a959dcda..30d47b87 100644
--- a/irc.h
+++ b/irc.h
@@ -219,6 +219,7 @@ void irc_umode_set( irc_t *irc, const char *s, gboolean allow_priv );
/* irc_channel.c */
irc_channel_t *irc_channel_new( irc_t *irc, const char *name );
irc_channel_t *irc_channel_by_name( irc_t *irc, const char *name );
+irc_channel_t *irc_channel_get( irc_t *irc, char *id );
int irc_channel_free( irc_channel_t *ic );
int irc_channel_add_user( irc_channel_t *ic, irc_user_t *iu );
int irc_channel_del_user( irc_channel_t *ic, irc_user_t *iu, gboolean silent, const char *msg );
diff --git a/irc_channel.c b/irc_channel.c
index b3904d22..8abc0486 100644
--- a/irc_channel.c
+++ b/irc_channel.c
@@ -48,7 +48,7 @@ irc_channel_t *irc_channel_new( irc_t *irc, const char *name )
strcmp( set_getstr( &irc->b->set, "ops" ), "root" ) == 0 )
irc_channel_user_set_mode( ic, irc->root, IRC_CHANNEL_USER_OP );
- irc->channels = g_slist_prepend( irc->channels, ic );
+ irc->channels = g_slist_append( irc->channels, ic );
set_add( &ic->set, "type", "control", set_eval_channel_type, ic );
@@ -68,13 +68,53 @@ irc_channel_t *irc_channel_by_name( irc_t *irc, const char *name )
{
irc_channel_t *ic = l->data;
- if( name[0] == ic->name[0] && nick_cmp( name + 1, ic->name + 1 ) == 0 )
+ if( g_strcasecmp( name, ic->name ) == 0 )
return ic;
}
return NULL;
}
+irc_channel_t *irc_channel_get( irc_t *irc, char *id )
+{
+ irc_channel_t *ic, *ret = NULL;
+ GSList *l;
+ int nr;
+
+ if( sscanf( id, "%d", &nr ) == 1 && nr < 1000 )
+ {
+ for( l = irc->channels; l; l = l->next )
+ {
+ ic = l->data;
+ if( ( nr-- ) == 0 )
+ return ic;
+ }
+
+ return NULL;
+ }
+
+ /* Exact match first: Partial match only sucks if there's a channel
+ #aa and #aabb */
+ if( ( ret = irc_channel_by_name( irc, id ) ) )
+ return ret;
+
+ for( l = irc->channels; l; l = l->next )
+ {
+ ic = l->data;
+
+ if( strstr( ic->name, id ) )
+ {
+ /* Make sure it's a unique match. */
+ if( !ret )
+ ret = ic;
+ else
+ return NULL;
+ }
+ }
+
+ return ret;
+}
+
int irc_channel_free( irc_channel_t *ic )
{
irc_t *irc = ic->irc;
diff --git a/root_commands.c b/root_commands.c
index bb9b26cd..72dec6f1 100644
--- a/root_commands.c
+++ b/root_commands.c
@@ -521,7 +521,7 @@ static set_t **cmd_channel_set_findhead( irc_t *irc, char *id )
{
irc_channel_t *ic;
- if( ( ic = irc_channel_by_name( irc, id ) ) )
+ if( ( ic = irc_channel_get( irc, id ) ) )
return &ic->set;
else
return NULL;
@@ -535,6 +535,26 @@ static void cmd_channel( irc_t *irc, char **cmd )
cmd_set_real( irc, cmd + 1, cmd_channel_set_findhead, NULL );
}
+ else if( g_strcasecmp( cmd[1], "list" ) == 0 )
+ {
+ GSList *l;
+ int i = 0;
+
+ if( strchr( irc->umode, 'b' ) )
+ irc_usermsg( irc, "Channel list:" );
+
+ for( l = irc->channels; l; l = l->next )
+ {
+ irc_channel_t *ic = l->data;
+
+ irc_usermsg( irc, "%2d. %s, %s channel%s", i, ic->name,
+ set_getstr( &ic->set, "type" ),
+ ic->flags & IRC_CHANNEL_JOINED ? " (joined)" : "" );
+
+ i ++;
+ }
+ irc_usermsg( irc, "End of channel list" );
+ }
else
{
irc_usermsg( irc, "Unknown command: %s %s. Please use \x02help commands\x02 to get a list of available commands.", "channel", cmd[1] );