1
0
Fork 0
forked from murx/irc9

Run optional commands after startup channel joins

This commit is contained in:
Johannes Findeisen 2026-11-29 03:58:20 +01:00
commit e138004be9
3 changed files with 159 additions and 102 deletions

View file

@ -92,8 +92,10 @@ negotiation when configured and before startup channel joins.
To enable startup channel joins, build with `make -B AUTOJOIN=1`. Add one To enable startup channel joins, build with `make -B AUTOJOIN=1`. Add one
`channel #name` line per channel below the corresponding `server` line. `channel #name` line per channel below the corresponding `server` line.
irc9 sends the joins when that server first confirms registration. Default irc9 sends the joins when that server first confirms registration. To run a
builds ignore `channel` lines. Use `make -B` to rebuild with autojoin disabled. slash command once the server confirms the channel join, add it after the
channel name. For example, `channel #channel /msg ChanServ OP #channel nickname`.
Commands run in the joined channel's context. Default builds ignore `channel` lines. Use `make -B` to rebuild with autojoin disabled.
Blank lines and whole-line comments starting with `#` are ignored. Blank lines and whole-line comments starting with `#` are ignored.
TLS certificates are verified against a system CA bundle when one is found. TLS certificates are verified against a system CA bundle when one is found.

253
irc9.c
View file

@ -90,6 +90,7 @@ typedef struct Window {
#ifdef USE_AUTOJOIN #ifdef USE_AUTOJOIN
typedef struct AutojoinChannel { typedef struct AutojoinChannel {
char name[CHANLEN]; char name[CHANLEN];
char *command;
struct AutojoinChannel *next; struct AutojoinChannel *next;
} AutojoinChannel; } AutojoinChannel;
#endif #endif
@ -124,6 +125,7 @@ typedef struct Server {
#endif #endif
#ifdef USE_AUTOJOIN #ifdef USE_AUTOJOIN
AutojoinChannel *autojoin; AutojoinChannel *autojoin;
AutojoinChannel *pending_autojoin;
#endif #endif
struct Server *next; struct Server *next;
} Server; } Server;
@ -672,6 +674,26 @@ static void load_config(const char *path)
continue; continue;
} }
a1 = strtok_r(NULL, " \t", &save); a1 = strtok_r(NULL, " \t", &save);
if (strcasecmp(key, "channel") == 0) {
#ifdef USE_AUTOJOIN
if (channel_tail && a1 && strlen(a1) < CHANLEN) {
AutojoinChannel *channel = xmalloc(sizeof *channel);
strcpy(channel->name, a1);
channel->command = NULL;
channel->next = NULL;
*channel_tail = channel;
channel_tail = &channel->next;
save += strspn(save, " \t");
if (*save == '/' && save[1] && strlen(save) < MAXINPUT &&
!strchr(save, '\r'))
channel->command = dupstr(save);
else if (*save)
fprintf(stderr, "irc9: ignoring invalid command for channel %s\n", a1);
}
#endif
continue;
}
a2 = strtok_r(NULL, " \t", &save); a2 = strtok_r(NULL, " \t", &save);
a3 = strtok_r(NULL, " \t", &save); a3 = strtok_r(NULL, " \t", &save);
@ -711,16 +733,6 @@ static void load_config(const char *path)
strcasecmp(key, "stripfmt") == 0) && a1) { strcasecmp(key, "stripfmt") == 0) && a1) {
strip_formatting = !strcasecmp(a1, "on") || !strcasecmp(a1, "true") || strip_formatting = !strcasecmp(a1, "on") || !strcasecmp(a1, "true") ||
!strcasecmp(a1, "yes") || strcmp(a1, "1") == 0; !strcasecmp(a1, "yes") || strcmp(a1, "1") == 0;
} else if (strcasecmp(key, "channel") == 0) {
#ifdef USE_AUTOJOIN
if (channel_tail && a1 && strlen(a1) < CHANLEN) {
AutojoinChannel *channel = xmalloc(sizeof *channel);
strcpy(channel->name, a1);
channel->next = NULL;
*channel_tail = channel;
channel_tail = &channel->next;
}
#endif
} else { } else {
fprintf(stderr, "irc9: ignoring config line: %s\n", line); fprintf(stderr, "irc9: ignoring config line: %s\n", line);
} }
@ -992,6 +1004,18 @@ static void handle_connect_results(void)
} }
} }
#ifdef USE_AUTOJOIN
static void free_autojoin(AutojoinChannel **head)
{
while (*head) {
AutojoinChannel *channel = *head;
*head = channel->next;
free(channel->command);
free(channel);
}
}
#endif
static void disconnect_server(Server *s) static void disconnect_server(Server *s)
{ {
s->connect_gen++; s->connect_gen++;
@ -1007,6 +1031,9 @@ static void disconnect_server(Server *s)
s->cap_state = CAP_NONE; s->cap_state = CAP_NONE;
s->caps[0] = 0; s->caps[0] = 0;
s->retry_at = time(NULL) + RETRY; s->retry_at = time(NULL) + RETRY;
#ifdef USE_AUTOJOIN
free_autojoin(&s->pending_autojoin);
#endif
} }
/* ------------------------------------------------------------------ */ /* ------------------------------------------------------------------ */
@ -1138,6 +1165,24 @@ static int handle_ctcp(Server *s, const char *nick, char *text,
return 1; return 1;
} }
#ifdef USE_AUTOJOIN
static void do_command(Window *window, char *line);
static void run_autojoin_command(Window *w)
{
AutojoinChannel **link = &w->srv->pending_autojoin;
while (*link && strcasecmp((*link)->name, w->name) != 0)
link = &(*link)->next;
if (!*link) return;
AutojoinChannel *channel = *link;
*link = channel->next;
do_command(w, channel->command);
free(channel->command);
free(channel);
}
#endif
static void handle_line(Server *s, char *line) static void handle_line(Server *s, char *line)
{ {
char *prefix, *cmd; char *prefix, *cmd;
@ -1232,6 +1277,9 @@ static void handle_line(Server *s, char *line)
Window *w = window_get(s, arg[0], W_CHANNEL); Window *w = window_get(s, arg[0], W_CHANNEL);
member_add(w, nick); member_add(w, nick);
if (!silent) append_nickf(w, "* ", hostmask ? hostmask : "someone", " ", "joined %s", arg[0]); if (!silent) append_nickf(w, "* ", hostmask ? hostmask : "someone", " ", "joined %s", arg[0]);
#ifdef USE_AUTOJOIN
if (strcasecmp(nick, s->nick) == 0) run_autojoin_command(w);
#endif
return; return;
} }
@ -1528,11 +1576,18 @@ static void handle_line(Server *s, char *line)
if (first_welcome && s->autocommand) if (first_welcome && s->autocommand)
sendf(s, "%s", s->autocommand); sendf(s, "%s", s->autocommand);
#ifdef USE_AUTOJOIN #ifdef USE_AUTOJOIN
AutojoinChannel **pending = &s->pending_autojoin;
while (s->autojoin) { while (s->autojoin) {
AutojoinChannel *channel = s->autojoin; AutojoinChannel *channel = s->autojoin;
sendf(s, "JOIN %s", channel->name);
s->autojoin = channel->next; s->autojoin = channel->next;
free(channel); sendf(s, "JOIN %s", channel->name);
if (channel->command) {
channel->next = NULL;
*pending = channel;
pending = &channel->next;
} else {
free(channel);
}
} }
#endif #endif
appendf(sw, "%s", narg > 0 ? arg[narg - 1] : cmd); appendf(sw, "%s", narg > 0 ? arg[narg - 1] : cmd);
@ -1573,6 +1628,7 @@ static void read_server(Server *s)
s->inbuf[s->inlen] = 0; s->inbuf[s->inlen] = 0;
if (s->inlen) handle_line(s, s->inbuf); if (s->inlen) handle_line(s, s->inbuf);
s->inlen = 0; s->inlen = 0;
if (s->fd < 0 || quit_flag) return;
} else if (s->inlen < sizeof s->inbuf - 1) { } else if (s->inlen < sizeof s->inbuf - 1) {
s->inbuf[s->inlen++] = c; s->inbuf[s->inlen++] = c;
} else { } else {
@ -1794,13 +1850,13 @@ static char *next_word(char **p)
return s; return s;
} }
static Window *input_target(void) static Window *input_target(Window *window)
{ {
if (!curwin || curwin->type == W_SERVER) return NULL; if (!window || window->type == W_SERVER) return NULL;
return curwin; return window;
} }
static void do_command(char *line) static void do_command(Window *window, char *line)
{ {
char *p = line + 1; char *p = line + 1;
while (*p == ' ' || *p == '\t') p++; while (*p == ' ' || *p == '\t') p++;
@ -1813,26 +1869,26 @@ static void do_command(char *line)
if (strcasecmp(cmd, "join") == 0 || strcasecmp(cmd, "j") == 0) { if (strcasecmp(cmd, "join") == 0 || strcasecmp(cmd, "j") == 0) {
char *chan = next_word(&q); char *chan = next_word(&q);
char chanbuf[CHANLEN]; char chanbuf[CHANLEN];
if (!chan || !curwin) return; if (!chan || !window) return;
if (!is_channel(chan)) { if (!is_channel(chan)) {
snprintf(chanbuf, sizeof chanbuf, "#%s", chan); snprintf(chanbuf, sizeof chanbuf, "#%s", chan);
chan = chanbuf; chan = chanbuf;
} }
Window *w = window_get(curwin->srv, chan, W_CHANNEL); Window *w = window_get(window->srv, chan, W_CHANNEL);
w->syncing = 1; w->syncing = 1;
clock_gettime(CLOCK_MONOTONIC, &w->join_ts); clock_gettime(CLOCK_MONOTONIC, &w->join_ts);
focus_window(w); focus_window(w);
sendf(curwin->srv, "JOIN %s", chan); sendf(window->srv, "JOIN %s", chan);
} else if (strcasecmp(cmd, "n") == 0 || strcasecmp(cmd, "names") == 0) { } else if (strcasecmp(cmd, "n") == 0 || strcasecmp(cmd, "names") == 0) {
Window *t = curwin; Window *t = window;
char *name = next_word(&q); char *name = next_word(&q);
if (name && curwin) { if (name && window) {
t = window_find(curwin->srv, name); t = window_find(window->srv, name);
if (!t) appendf(curwin, "* no such window: %s", name); if (!t) appendf(window, "* no such window: %s", name);
} }
if (t) show_names(t); if (t) show_names(t);
} else if (strcasecmp(cmd, "part") == 0 || strcasecmp(cmd, "leave") == 0) { } else if (strcasecmp(cmd, "part") == 0 || strcasecmp(cmd, "leave") == 0) {
Window *t = input_target(); Window *t = input_target(window);
char *chan = next_word(&q); char *chan = next_word(&q);
if (!t || !t->srv) return; if (!t || !t->srv) return;
if (!chan && t->type == W_CHANNEL) chan = t->name; if (!chan && t->type == W_CHANNEL) chan = t->name;
@ -1841,37 +1897,37 @@ static void do_command(char *line)
else sendf(t->srv, "PART %s", chan); else sendf(t->srv, "PART %s", chan);
} else if (strcasecmp(cmd, "nick") == 0) { } else if (strcasecmp(cmd, "nick") == 0) {
char *newnick = next_word(&q); char *newnick = next_word(&q);
if (!newnick || !curwin) return; if (!newnick || !window) return;
sendf(curwin->srv, "NICK %s", newnick); sendf(window->srv, "NICK %s", newnick);
appendf(serverwin(curwin->srv), "* changing nick to %s", newnick); appendf(serverwin(window->srv), "* changing nick to %s", newnick);
} else if (strcasecmp(cmd, "msg") == 0) { } else if (strcasecmp(cmd, "msg") == 0) {
char *target = next_word(&q); char *target = next_word(&q);
if (!target || !curwin || !*q) return; if (!target || !window || !*q) return;
sendf(curwin->srv, "PRIVMSG %s :%s", target, q); sendf(window->srv, "PRIVMSG %s :%s", target, q);
Window *w = window_get(curwin->srv, target, Window *w = window_get(window->srv, target,
is_channel(target) ? W_CHANNEL : W_QUERY); is_channel(target) ? W_CHANNEL : W_QUERY);
append_nickf(w, "<", curwin->srv->nick, "> ", "%s", q); append_nickf(w, "<", window->srv->nick, "> ", "%s", q);
} else if (strcasecmp(cmd, "whois") == 0) { } else if (strcasecmp(cmd, "whois") == 0) {
char *nick = next_word(&q); char *nick = next_word(&q);
if (!curwin) return; if (!window) return;
if (!nick) { appendf(curwin, "* usage: /whois nick"); return; } if (!nick) { appendf(window, "* usage: /whois nick"); return; }
curwin->srv->reply_win = curwin; window->srv->reply_win = window;
sendf(curwin->srv, "WHOIS %s", nick); sendf(window->srv, "WHOIS %s", nick);
appendf(curwin, "* whois %s", nick); appendf(window, "* whois %s", nick);
} else if (strcasecmp(cmd, "me") == 0) { } else if (strcasecmp(cmd, "me") == 0) {
Window *t = input_target(); Window *t = input_target(window);
if (!t || !*q) return; if (!t || !*q) return;
sendf(t->srv, "PRIVMSG %s :\001ACTION %s\001", t->name, q); sendf(t->srv, "PRIVMSG %s :\001ACTION %s\001", t->name, q);
append_nickf(t, "* ", t->srv->nick, " ", "%s", q); append_nickf(t, "* ", t->srv->nick, " ", "%s", q);
} else if (strcasecmp(cmd, "away") == 0) { } else if (strcasecmp(cmd, "away") == 0) {
if (!curwin) return; if (!window) return;
sendf(curwin->srv, "AWAY :%s", *q ? q : ""); sendf(window->srv, "AWAY :%s", *q ? q : "");
if (*q) appendf(curwin, "* away: %s", q); if (*q) appendf(window, "* away: %s", q);
else appendf(curwin, "* not away"); else appendf(window, "* not away");
} else if (strcasecmp(cmd, "topic") == 0) { } else if (strcasecmp(cmd, "topic") == 0) {
Window *t = input_target(); Window *t = input_target(window);
if (!t || t->type != W_CHANNEL) { if (!t || t->type != W_CHANNEL) {
if (curwin) appendf(curwin, "* no channel here"); if (window) appendf(window, "* no channel here");
return; return;
} }
t->srv->reply_win = t; t->srv->reply_win = t;
@ -1879,36 +1935,36 @@ static void do_command(char *line)
else sendf(t->srv, "TOPIC %s", t->name); else sendf(t->srv, "TOPIC %s", t->name);
} else if (strcasecmp(cmd, "invite") == 0) { } else if (strcasecmp(cmd, "invite") == 0) {
char *nick = next_word(&q); char *nick = next_word(&q);
if (!nick || !curwin) return; if (!nick || !window) return;
char *chan = next_word(&q); char *chan = next_word(&q);
if (!chan && curwin->type == W_CHANNEL) chan = curwin->name; if (!chan && window->type == W_CHANNEL) chan = window->name;
if (!chan) { appendf(curwin, "* usage: /invite nick [#chan]"); return; } if (!chan) { appendf(window, "* usage: /invite nick [#chan]"); return; }
curwin->srv->reply_win = curwin; window->srv->reply_win = window;
sendf(curwin->srv, "INVITE %s %s", nick, chan); sendf(window->srv, "INVITE %s %s", nick, chan);
appendf(curwin, "* inviting %s to %s", nick, chan); appendf(window, "* inviting %s to %s", nick, chan);
} else if (strcasecmp(cmd, "kick") == 0) { } else if (strcasecmp(cmd, "kick") == 0) {
Window *t = input_target(); Window *t = input_target(window);
char *nick = next_word(&q); char *nick = next_word(&q);
if (!t || t->type != W_CHANNEL || !nick) { if (!t || t->type != W_CHANNEL || !nick) {
if (curwin) appendf(curwin, "* usage: /kick nick [reason] in a channel"); if (window) appendf(window, "* usage: /kick nick [reason] in a channel");
return; return;
} }
if (*q) sendf(t->srv, "KICK %s %s :%s", t->name, nick, q); if (*q) sendf(t->srv, "KICK %s %s :%s", t->name, nick, q);
else sendf(t->srv, "KICK %s %s", t->name, nick); else sendf(t->srv, "KICK %s %s", t->name, nick);
} else if (strcasecmp(cmd, "mode") == 0) { } else if (strcasecmp(cmd, "mode") == 0) {
char *target = next_word(&q); char *target = next_word(&q);
if (!target && curwin && curwin->type != W_SERVER) target = curwin->name; if (!target && window && window->type != W_SERVER) target = window->name;
if (!target || !curwin) return; if (!target || !window) return;
curwin->srv->reply_win = curwin; window->srv->reply_win = window;
if (*q) sendf(curwin->srv, "MODE %s %s", target, q); if (*q) sendf(window->srv, "MODE %s %s", target, q);
else sendf(curwin->srv, "MODE %s", target); else sendf(window->srv, "MODE %s", target);
} else if (strcasecmp(cmd, "op") == 0 || strcasecmp(cmd, "deop") == 0 || } else if (strcasecmp(cmd, "op") == 0 || strcasecmp(cmd, "deop") == 0 ||
strcasecmp(cmd, "voice") == 0 || strcasecmp(cmd, "devoice") == 0 || strcasecmp(cmd, "voice") == 0 || strcasecmp(cmd, "devoice") == 0 ||
strcasecmp(cmd, "ban") == 0 || strcasecmp(cmd, "unban") == 0) { strcasecmp(cmd, "ban") == 0 || strcasecmp(cmd, "unban") == 0) {
Window *t = input_target(); Window *t = input_target(window);
char *who = next_word(&q); char *who = next_word(&q);
if (!t || t->type != W_CHANNEL || !who) { if (!t || t->type != W_CHANNEL || !who) {
if (curwin) appendf(curwin, "* usage: /%s nick|mask in a channel", cmd); if (window) appendf(window, "* usage: /%s nick|mask in a channel", cmd);
return; return;
} }
const char *flag = !strcasecmp(cmd, "op") ? "+o" : const char *flag = !strcasecmp(cmd, "op") ? "+o" :
@ -1920,58 +1976,58 @@ static void do_command(char *line)
appendf(t, "* mode %s %s %s", t->name, flag, who); appendf(t, "* mode %s %s %s", t->name, flag, who);
} else if (strcasecmp(cmd, "notice") == 0) { } else if (strcasecmp(cmd, "notice") == 0) {
char *target = next_word(&q); char *target = next_word(&q);
if (!target || !curwin || !*q) return; if (!target || !window || !*q) return;
sendf(curwin->srv, "NOTICE %s :%s", target, q); sendf(window->srv, "NOTICE %s :%s", target, q);
Window *w = window_get(curwin->srv, target, Window *w = window_get(window->srv, target,
is_channel(target) ? W_CHANNEL : W_QUERY); is_channel(target) ? W_CHANNEL : W_QUERY);
append_nickf(w, "-", curwin->srv->nick, "- ", "%s", q); append_nickf(w, "-", window->srv->nick, "- ", "%s", q);
} else if (strcasecmp(cmd, "query") == 0) { } else if (strcasecmp(cmd, "query") == 0) {
char *nick = next_word(&q); char *nick = next_word(&q);
if (!curwin) return; if (!window) return;
if (nick) focus_window(window_get(curwin->srv, nick, W_QUERY)); if (nick) focus_window(window_get(window->srv, nick, W_QUERY));
else if (curwin->type == W_QUERY) window_close(curwin->srv, curwin); else if (window->type == W_QUERY) window_close(window->srv, window);
} else if (strcasecmp(cmd, "who") == 0) { } else if (strcasecmp(cmd, "who") == 0) {
if (!curwin) return; if (!window) return;
curwin->srv->reply_win = curwin; window->srv->reply_win = window;
sendf(curwin->srv, "WHO%s%s", *q ? " " : "", q); sendf(window->srv, "WHO%s%s", *q ? " " : "", q);
} else if (strcasecmp(cmd, "list") == 0) { } else if (strcasecmp(cmd, "list") == 0) {
if (!curwin) return; if (!window) return;
curwin->srv->reply_win = curwin; window->srv->reply_win = window;
sendf(curwin->srv, "LIST%s%s", *q ? " " : "", q); sendf(window->srv, "LIST%s%s", *q ? " " : "", q);
} else if (strcasecmp(cmd, "motd") == 0 || strcasecmp(cmd, "time") == 0 || } else if (strcasecmp(cmd, "motd") == 0 || strcasecmp(cmd, "time") == 0 ||
strcasecmp(cmd, "version") == 0 || strcasecmp(cmd, "admin") == 0 || strcasecmp(cmd, "version") == 0 || strcasecmp(cmd, "admin") == 0 ||
strcasecmp(cmd, "info") == 0 || strcasecmp(cmd, "links") == 0 || strcasecmp(cmd, "info") == 0 || strcasecmp(cmd, "links") == 0 ||
strcasecmp(cmd, "lusers") == 0 || strcasecmp(cmd, "stats") == 0) { strcasecmp(cmd, "lusers") == 0 || strcasecmp(cmd, "stats") == 0) {
if (!curwin) return; if (!window) return;
curwin->srv->reply_win = curwin; window->srv->reply_win = window;
sendf(curwin->srv, "%s%s%s", cmd, *q ? " " : "", q); sendf(window->srv, "%s%s%s", cmd, *q ? " " : "", q);
appendf(curwin, "* %s", cmd); appendf(window, "* %s", cmd);
} else if (strcasecmp(cmd, "ping") == 0) { } else if (strcasecmp(cmd, "ping") == 0) {
char *nick = next_word(&q); char *nick = next_word(&q);
if (!nick || !curwin) return; if (!nick || !window) return;
sendf(curwin->srv, "PING %s", nick); sendf(window->srv, "PING %s", nick);
appendf(curwin, "* pinging %s", nick); appendf(window, "* pinging %s", nick);
} else if (strcasecmp(cmd, "ctcp") == 0) { } else if (strcasecmp(cmd, "ctcp") == 0) {
char *nick = next_word(&q); char *nick = next_word(&q);
if (!nick || !curwin || !*q) return; if (!nick || !window || !*q) return;
sendf(curwin->srv, "PRIVMSG %s :\001%s\001", nick, q); sendf(window->srv, "PRIVMSG %s :\001%s\001", nick, q);
appendf(curwin, "* ctcp %s %s", nick, q); appendf(window, "* ctcp %s %s", nick, q);
} else if (strcasecmp(cmd, "raw") == 0) { } else if (strcasecmp(cmd, "raw") == 0) {
if (!curwin || !*q) return; if (!window || !*q) return;
sendf(curwin->srv, "%s", q); sendf(window->srv, "%s", q);
appendf(curwin, "* -> %s", q); appendf(window, "* -> %s", q);
} else if (strcasecmp(cmd, "close") == 0 || strcasecmp(cmd, "wc") == 0) { } else if (strcasecmp(cmd, "close") == 0 || strcasecmp(cmd, "wc") == 0) {
if (!curwin) return; if (!window) return;
if (curwin == curwin->srv->windows) { if (window == window->srv->windows) {
appendf(curwin, "* cannot close the server window"); appendf(window, "* cannot close the server window");
return; return;
} }
window_close(curwin->srv, curwin); window_close(window->srv, window);
} else if (strcasecmp(cmd, "clear") == 0) { } else if (strcasecmp(cmd, "clear") == 0) {
window_clear(curwin); window_clear(window);
} else if (strcasecmp(cmd, "reconnect") == 0) { } else if (strcasecmp(cmd, "reconnect") == 0) {
if (!curwin) return; if (!window) return;
Server *s = curwin->srv; Server *s = window->srv;
appendf(serverwin(s), "* reconnecting to %s:%d", s->host, s->port); appendf(serverwin(s), "* reconnecting to %s:%d", s->host, s->port);
disconnect_server(s); disconnect_server(s);
s->retry_at = 0; s->retry_at = 0;
@ -1981,7 +2037,7 @@ static void do_command(char *line)
sendf(s, "QUIT :%s", *q ? q : "irc9"); sendf(s, "QUIT :%s", *q ? q : "irc9");
quit_flag = 1; quit_flag = 1;
} else if (strcasecmp(cmd, "help") == 0) { } else if (strcasecmp(cmd, "help") == 0) {
Window *t = curwin ? curwin : server_window_owner()->windows; Window *t = window ? window : server_window_owner()->windows;
appendf(t, "commands: /join /part /leave /nick /msg /me /whois /n /names"); appendf(t, "commands: /join /part /leave /nick /msg /me /whois /n /names");
appendf(t, " /away /topic /invite /kick /mode /notice /query"); appendf(t, " /away /topic /invite /kick /mode /notice /query");
appendf(t, " /who /list /motd /time /version /admin /info"); appendf(t, " /who /list /motd /time /version /admin /info");
@ -1991,7 +2047,7 @@ static void do_command(char *line)
appendf(t, "keys: ctrl-n / ctrl-p switch windows, pgup/pgdn scroll, ctrl-l clear screen"); appendf(t, "keys: ctrl-n / ctrl-p switch windows, pgup/pgdn scroll, ctrl-l clear screen");
appendf(t, " ctrl-s save scrollback, ctrl-t toggle copy view"); appendf(t, " ctrl-s save scrollback, ctrl-t toggle copy view");
} else { } else {
if (curwin) appendf(curwin, "* unknown command: /%s", cmd); if (window) appendf(window, "* unknown command: /%s", cmd);
} }
} }
@ -2002,9 +2058,9 @@ static void submit_input(void)
history_add(line); history_add(line);
if (*line == '/') { if (*line == '/') {
do_command(line); do_command(curwin, line);
} else if (*line) { } else if (*line) {
Window *t = input_target(); Window *t = input_target(curwin);
if (!t) { if (!t) {
if (curwin) appendf(curwin, "* no target here; use /join or /msg"); if (curwin) appendf(curwin, "* no target here; use /join or /msg");
} else { } else {
@ -2906,11 +2962,8 @@ int main(int argc, char **argv)
#endif #endif
if (s->fd >= 0) close(s->fd); if (s->fd >= 0) close(s->fd);
#ifdef USE_AUTOJOIN #ifdef USE_AUTOJOIN
while (s->autojoin) { free_autojoin(&s->autojoin);
AutojoinChannel *channel = s->autojoin; free_autojoin(&s->pending_autojoin);
s->autojoin = channel->next;
free(channel);
}
#endif #endif
free(s->name); free(s->name);
free(s->autocommand); free(s->autocommand);

View file

@ -18,6 +18,8 @@ name Libera Chat
# autocommand /msg NickServ IDENTIFY irc9user $PASSWORD # autocommand /msg NickServ IDENTIFY irc9user $PASSWORD
# Build with make -B AUTOJOIN=1 and uncomment channel lines to join at startup. # Build with make -B AUTOJOIN=1 and uncomment channel lines to join at startup.
# Each channel line applies to the server above it. # Each channel line applies to the server above it.
# An optional slash command runs after the channel join succeeds.
# channel #channel /msg ChanServ OP #channel nickname
channel #irc9 channel #irc9
# channel #murx # channel #murx
# channel #zynk # channel #zynk