1
0
Fork 0
forked from murx/irc9

Add per-server autocommand configuration

This commit is contained in:
Johannes Findeisen 2026-11-27 18:31:56 +01:00
commit 2dc64f7d1e
3 changed files with 27 additions and 1 deletions

View file

@ -57,6 +57,12 @@ TLS; use port `6697` for Libera and OFTC. A `sasl <user> <pass>` line applies to
the most recent `server` line and enables SASL PLAIN for that server only. The
SASL user is your account name (for many people this is the same as the nick).
Place an optional `autocommand <IRC command>` below the corresponding
`server` line, immediately after its `sasl` line when present. For example,
`autocommand PRIVMSG NickServ :STATUS mynick` sends that raw IRC command.
It runs once per successful registration, including reconnects, after SASL
negotiation when configured and before startup channel joins.
To enable startup channel joins, build with `make -B AUTOJOIN=1`. Add one
`channel #name` line per channel below the corresponding `server` line.
irc9 sends the joins when that server first confirms registration. Default

17
irc9.c
View file

@ -106,6 +106,7 @@ typedef struct Server {
int sasl;
char sasl_user[NICKLEN];
char sasl_pass[128];
char *autocommand;
int cap_state;
char caps[512]; /* accumulated multi-line CAP LS reply */
char umode[32];
@ -567,6 +568,18 @@ static void load_config(const char *path)
char *save = NULL;
key = strtok_r(p, " \t", &save);
if (!key) continue;
if (strcasecmp(key, "autocommand") == 0) {
save += strspn(save, " \t");
if (last && *save && strlen(save) <= MAXLINE - 2 &&
!strchr(save, '\r')) {
free(last->autocommand);
last->autocommand = dupstr(save);
} else {
fprintf(stderr, "irc9: autocommand requires a server and an IRC command of at most %d bytes\n",
MAXLINE - 2);
}
continue;
}
a1 = strtok_r(NULL, " \t", &save);
a2 = strtok_r(NULL, " \t", &save);
a3 = strtok_r(NULL, " \t", &save);
@ -1410,7 +1423,10 @@ static void handle_line(Server *s, char *line)
}
if (strcmp(cmd, "001") == 0) {
int first_welcome = !s->connected;
s->connected = 1;
if (first_welcome && s->autocommand)
sendf(s, "%s", s->autocommand);
#ifdef USE_AUTOJOIN
while (s->autojoin) {
AutojoinChannel *channel = s->autojoin;
@ -2598,6 +2614,7 @@ int main(int argc, char **argv)
free(channel);
}
#endif
free(s->autocommand);
free(s);
s = sn;
}

View file

@ -8,12 +8,15 @@ real Armin
# Libera and OFTC use TLS on 6697. Use port 6667 without the ssl keyword for
# plain TCP. The optional sasl line applies to the server above it; the SASL
# user is your account name.
# user is your account name. An optional autocommand sends one raw IRC command
# after registration on the server above it, before startup channel joins.
server irc.libera.chat 6697 ssl
# sasl armin my-sasl-password
# autocommand PRIVMSG NickServ :STATUS armin
server irc.oftc.net 6697 ssl
# sasl armin my-sasl-password
# autocommand PRIVMSG NickServ :STATUS armin
# Build with make -B AUTOJOIN=1 and uncomment channel lines to join at startup.
# Each channel line applies to the server above it.