hirc

IRC client
Log | Files | Refs

commit 0db89ece6ee58ffc0e00102680e54c4d17e70d00
parent ce2c8d6069074e40fe50ec15e94654a987ec67cf
Author: hhvn <dev@hhvn.uk>
Date:   Sat, 12 Mar 2022 23:24:57 +0000

Add /invite

Diffstat:
Msrc/commands.c | 30++++++++++++++++++++++++++++++
Msrc/config.c | 7++++++-
Msrc/handle.c | 30++++++++++++++++++++++++++++++
Msrc/ui.c | 1+
4 files changed, 67 insertions(+), 1 deletion(-)

diff --git a/src/commands.c b/src/commands.c @@ -35,6 +35,16 @@ #define COMMAND(func) static void func(struct Server *server, struct Channel *channel, char *str) +/* + * There are some commands that may be useful that I haven't bothered to implement. + * + * /notify may be useful but would require storing data in the server, and the + * ability to perform actions at certain time intervals. + * + * I don't think I have ever used /knock + * + */ + /* IRC commands */ COMMAND(command_away); COMMAND(command_msg); @@ -65,6 +75,7 @@ COMMAND(command_kill); COMMAND(command_links); COMMAND(command_map); COMMAND(command_lusers); +COMMAND(command_invite); /* Channel priviledges (use modelset only) */ COMMAND(command_op); @@ -212,6 +223,9 @@ struct Command commands[] = { "usage: /map", "Similar to /links but prints an ascii diagram.", "Nonstandard feature.", NULL}}, + {"invite", command_invite, 1, { + "usage: /invite <nick> [channel]", + "Invite a nick to the current or specified channel.", NULL}}, /* Channel priviledges */ {"op", command_op, 2, { "usage: /op nicks...", @@ -1863,6 +1877,22 @@ command_unban) { modelset("unban", server, channel, 1, 'b', str); } +COMMAND( +command_invite) { + char *nick, *chan; + + if (!str) { + command_toofew("invite"); + return; + } + + nick = strtok_r(str, " ", &chan); + if (!chan) + chan = channel->name; + + ircprintf(server, "INVITE %s %s\r\n", nick, chan); +} + int command_getopt(char **str, struct CommandOpts *opts) { char *opt; diff --git a/src/config.c b/src/config.c @@ -494,6 +494,11 @@ struct Config config[] = { .strhandle = config_redraws, .description = { "Format of topic being set", NULL}}, + {"format.invite", 1, Val_string, + .str = "%{nick:${nick}}${nick}%{o} invited you to ${2}", + .strhandle = config_redraws, + .description = { + "Format of an invitation being received.", NULL}}, /* Generic numerics (bit boring) */ {"format.rpl.welcome", 1, Val_string, .str = "${2-}", @@ -807,7 +812,7 @@ struct Config config[] = { .description = { "Format of RPL_TOPIC (332) numeric", NULL}}, {"format.rpl.inviting", 1, Val_string, - .str = "${2-}", + .str = "invite%{=}${2}", .strhandle = config_redraws, .description = { "Format of RPL_INVITING (341) numeric", NULL}}, diff --git a/src/handle.c b/src/handle.c @@ -35,12 +35,14 @@ HANDLER(handle_NICK); HANDLER(handle_MODE); HANDLER(handle_TOPIC); HANDLER(handle_PRIVMSG); +HANDLER(handle_INVITE); HANDLER(handle_RPL_WELCOME); HANDLER(handle_RPL_ISUPPORT); HANDLER(handle_RPL_CHANNELMODEIS); HANDLER(handle_RPL_NOTOPIC); HANDLER(handle_RPL_TOPIC); HANDLER(handle_RPL_TOPICWHOTIME); +HANDLER(handle_RPL_INVITING); HANDLER(handle_RPL_NAMREPLY); HANDLER(handle_RPL_ENDOFNAMES); HANDLER(handle_RPL_ENDOFMOTD); @@ -61,6 +63,7 @@ struct Handler handlers[] = { { "TOPIC", handle_TOPIC }, { "PRIVMSG", handle_PRIVMSG }, { "NOTICE", handle_PRIVMSG }, + { "INVITE", handle_INVITE }, { "001", handle_RPL_WELCOME }, { "005", handle_RPL_ISUPPORT }, { "301", handle_RPL_AWAY }, @@ -72,6 +75,7 @@ struct Handler handlers[] = { * - it's annoyingly sent after MODE */ { "332", handle_RPL_TOPIC }, { "333", handle_RPL_TOPICWHOTIME }, + { "341", handle_RPL_INVITING }, { "353", handle_RPL_NAMREPLY }, { "366", handle_RPL_ENDOFNAMES }, { "376", handle_RPL_ENDOFMOTD }, @@ -294,6 +298,19 @@ handle_PRIVMSG) { } HANDLER( +handle_INVITE) { + struct Channel *priv; + + if (!msg->from || param_len(msg->params) < 3) + return; + + if ((priv = chan_get(&server->privs, msg->from->nick, -1)) != NULL) + hist_addp(priv->history, msg, Activity_status, HIST_DFL); + else + hist_addp(server->history, msg, Activity_status, HIST_DFL); +} + +HANDLER( handle_RPL_ISUPPORT) { char *key, *value; char **params = msg->params; @@ -355,6 +372,19 @@ handle_RPL_CHANNELMODEIS) { } HANDLER( +handle_RPL_INVITING) { + struct Channel *chan; + + if (param_len(msg->params) < 4) + return; + + if ((chan = chan_get(&server->channels, *(msg->params+3), -1)) == NULL) + chan = chan_add(server, &server->channels, *(msg->params+3), 0); + + hist_addp(chan->history, msg, Activity_status, HIST_DFL|HIST_SELF); +} + +HANDLER( handle_RPL_NAMREPLY) { struct Channel *chan; struct Nick *oldnick; diff --git a/src/ui.c b/src/ui.c @@ -103,6 +103,7 @@ struct { {"QUIT", "format.quit"}, {"NICK", "format.nick"}, {"TOPIC", "format.topic"}, + {"INVITE", "format.invite"}, /* START: misc/rpl-ui-gen.awk */ {"200", "format.rpl.tracelink"}, {"201", "format.rpl.traceconnecting"},