aboutsummaryrefslogtreecommitdiffstats
path: root/root_commands.c
diff options
context:
space:
mode:
Diffstat (limited to 'root_commands.c')
-rw-r--r--root_commands.c80
1 files changed, 75 insertions, 5 deletions
diff --git a/root_commands.c b/root_commands.c
index add9bceb..59974026 100644
--- a/root_commands.c
+++ b/root_commands.c
@@ -1234,8 +1234,10 @@ static void cmd_chat(irc_t *irc, char **cmd)
account_t *acc;
if (g_strcasecmp(cmd[1], "add") == 0) {
- char *channel, *s;
+ bee_chat_info_t *ci;
+ char *channel, *room, *s;
struct irc_channel *ic;
+ guint i;
MIN_ARGS(3);
@@ -1247,8 +1249,22 @@ static void cmd_chat(irc_t *irc, char **cmd)
return;
}
+ if (cmd[3][0] == '!') {
+ i = g_ascii_strtoull(cmd[3] + 1, NULL, 10);
+ ci = g_slist_nth_data(acc->ic->chatlist, i - 1);
+
+ if (ci == NULL) {
+ irc_rootmsg(irc, "Invalid chatroom index");
+ return;
+ }
+
+ room = ci->title;
+ } else {
+ room = cmd[3];
+ }
+
if (cmd[4] == NULL) {
- channel = g_strdup(cmd[3]);
+ channel = g_strdup(room);
if ((s = strchr(channel, '@'))) {
*s = 0;
}
@@ -1268,7 +1284,7 @@ static void cmd_chat(irc_t *irc, char **cmd)
set_setstr(&ic->set, "type", "chat") &&
set_setstr(&ic->set, "chat_type", "room") &&
set_setstr(&ic->set, "account", cmd[2]) &&
- set_setstr(&ic->set, "room", cmd[3])) {
+ set_setstr(&ic->set, "room", room)) {
irc_rootmsg(irc, "Chatroom successfully added.");
} else {
if (ic) {
@@ -1278,6 +1294,18 @@ static void cmd_chat(irc_t *irc, char **cmd)
irc_rootmsg(irc, "Could not add chatroom.");
}
g_free(channel);
+ } else if (g_strcasecmp(cmd[1], "list") == 0) {
+ MIN_ARGS(2);
+
+ if (!(acc = account_get(irc->b, cmd[2]))) {
+ irc_rootmsg(irc, "Invalid account");
+ return;
+ } else if (!acc->prpl->chat_list) {
+ irc_rootmsg(irc, "Existing chatrooms not supported on that account.");
+ return;
+ }
+
+ acc->prpl->chat_list(acc->ic, cmd[3]);
} else if (g_strcasecmp(cmd[1], "with") == 0) {
irc_user_t *iu;
@@ -1292,8 +1320,7 @@ static void cmd_chat(irc_t *irc, char **cmd)
} else {
irc_rootmsg(irc, "Can't open a groupchat with %s.", cmd[2]);
}
- } else if (g_strcasecmp(cmd[1], "list") == 0 ||
- g_strcasecmp(cmd[1], "set") == 0 ||
+ } else if (g_strcasecmp(cmd[1], "set") == 0 ||
g_strcasecmp(cmd[1], "del") == 0) {
irc_rootmsg(irc,
"Warning: The \002chat\002 command was mostly replaced with the \002channel\002 command.");
@@ -1305,6 +1332,49 @@ static void cmd_chat(irc_t *irc, char **cmd)
}
}
+void cmd_chat_list_finish(struct im_connection *ic)
+{
+ account_t *acc = ic->acc;
+ bee_chat_info_t *ci;
+ char *hformat, *iformat, *topic;
+ GSList *l;
+ GString *userc;
+ guint i = 0;
+ irc_t *irc = ic->bee->ui_data;
+
+ if (ic->chatlist == NULL) {
+ irc_rootmsg(irc, "No existing chatrooms");
+ return;
+ }
+
+ if (strchr(irc->umode, 'b') != NULL) {
+ hformat = "%s\t%s\t%s\t%s";
+ iformat = "%u\t%s\t%s\t%s";
+ } else {
+ hformat = "%s %-20s %s %s";
+ iformat = "%5u %-20.20s %5s %s";
+ }
+
+ irc_rootmsg(irc, hformat, "Index", "Title", "Users", "Topic");
+ userc = g_string_new(NULL);
+
+ for (l = ic->chatlist; l; l = l->next) {
+ ci = l->data;
+ topic = ci->topic ? ci->topic : "";
+
+ if (ci->userc >= 0) {
+ g_string_printf(userc, "%d", ci->userc);
+ } else {
+ g_string_assign(userc, "-");
+ }
+
+ irc_rootmsg(irc, iformat, ++i, ci->title, userc->str, topic);
+ }
+
+ irc_rootmsg(irc, "%u %s chatrooms", i, acc->tag);
+ g_string_free(userc, TRUE);
+}
+
static void cmd_group(irc_t *irc, char **cmd)
{
GSList *l;