commit 14e5a1c740731355db4e8024a0cd1576f3c44e48
parent fa2660385d64eac0fa2bb05158378be2bf7d4059
Author: hhvn <dev@hhvn.uk>
Date: Sat, 5 Feb 2022 18:40:18 +0000
s/commands.c s/handle.c s/ui.c s/config.c: /away
Diffstat:
4 files changed, 62 insertions(+), 8 deletions(-)
diff --git a/src/commands.c b/src/commands.c
@@ -33,6 +33,7 @@
#define command_toomany(cmd) ui_error("/%s: too many arguments", cmd)
#define command_needselected(cmd, type) ui_error("/%s: no %s selected", cmd, type)
+static void command_away(struct Server *server, char *str);
static void command_msg(struct Server *server, char *str);
static void command_notice(struct Server *server, char *str);
static void command_me(struct Server *server, char *str);
@@ -77,6 +78,10 @@ enum {
};
struct Command commands[] = {
+ {"away", command_away, 0, {
+ "usage: /away [message]",
+ "Set yourself as away on the server.",
+ "An empty message will unset the away.", NULL}},
{"msg", command_msg, 1, {
"usage: /msg <nick|channel> message..",
"Send a message to a nick or channel.",
@@ -219,6 +224,42 @@ struct Command commands[] = {
struct Alias *aliases = NULL;
static void
+command_away(struct Server *server, char *str) {
+ struct Server *sp;
+ char *format;
+ int all = 1, ret;
+ enum { opt_one };
+ static struct CommandOpts opts[] = {
+ {"one", CMD_NARG, opt_one},
+ {"NULL", 0, 0},
+ };
+
+ while ((ret = command_getopt(&str, opts)) != opt_done) {
+ switch (ret) {
+ case opt_error:
+ return;
+ case opt_one:
+ all = 0;
+ break;
+ }
+ }
+
+ if (str)
+ format = "AWAY :%s\r\n";
+ else
+ format = "AWAY\r\n";
+
+ if (all) {
+ for (sp = servers; sp; sp = sp->next)
+ ircprintf(sp, format, str);
+ } else if (server) {
+ ircprintf(server, format, str);
+ } else {
+ ui_error("-one specified, but no server selected", NULL);
+ }
+}
+
+static void
command_msg(struct Server *server, char *str) {
struct Channel *chan = NULL;
char *target, *message;
@@ -235,7 +276,7 @@ command_msg(struct Server *server, char *str) {
else
chan = chan_get(&server->privs, target, -1);
- ircprintf(selected.server, "PRIVMSG %s :%s\r\n", target, message);
+ ircprintf(server, "PRIVMSG %s :%s\r\n", target, message);
if (chan) {
hist_format(chan->history, Activity_self,
HIST_SHOW|HIST_LOG|HIST_SELF, "PRIVMSG %s :%s", target, message);
@@ -259,7 +300,7 @@ command_notice(struct Server *server, char *str) {
else
chan = chan_get(&server->privs, target, -1);
- ircprintf(selected.server, "NOTICE %s :%s\r\n", target, message);
+ ircprintf(server, "NOTICE %s :%s\r\n", target, message);
if (chan) {
hist_format(chan->history, Activity_self,
HIST_SHOW|HIST_LOG|HIST_SELF, "NOTICE %s :%s", target, message);
@@ -276,7 +317,7 @@ command_me(struct Server *server, char *str) {
if (!str)
str = "";
- ircprintf(selected.server, "PRIVMSG %s :%cACTION %s%c\r\n", selected.channel->name, 1, str, 1);
+ ircprintf(server, "PRIVMSG %s :%cACTION %s%c\r\n", selected.channel->name, 1, str, 1);
hist_format(selected.channel->history, Activity_self,
HIST_SHOW|HIST_LOG|HIST_SELF, "PRIVMSG %s :%cACTION %s%c", selected.channel->name, 1, str, 1);
}
diff --git a/src/config.c b/src/config.c
@@ -655,7 +655,7 @@ struct Config config[] = {
.description = {
"Format of RPL_NONE (300) numeric", NULL}},
{"format.rpl.away", 1, Val_string,
- .str = "${2-}",
+ .str = "away%{=}%{nick:${2}}${2}%{o}: ${3}",
.strhandle = config_redraws,
.description = {
"Format of RPL_AWAY (301) numeric", NULL}},
@@ -670,12 +670,12 @@ struct Config config[] = {
.description = {
"Format of RPL_ISON (303) numeric", NULL}},
{"format.rpl.unaway", 1, Val_string,
- .str = "${2-}",
+ .str = "%{c:40}<--%{o}%{=}No longer %{b}away%{b}",
.strhandle = config_redraws,
.description = {
"Format of RPL_UNAWAY (305) numeric", NULL}},
{"format.rpl.nowaway", 1, Val_string,
- .str = "${2-}",
+ .str = "%{c:32}-->%{o}%{=}Set %{b}away%{b}",
.strhandle = config_redraws,
.description = {
"Format of RPL_NOWAWAY (306) numeric", NULL}},
diff --git a/src/handle.c b/src/handle.c
@@ -45,6 +45,7 @@ HANDLER(handle_RPL_NAMREPLY);
HANDLER(handle_RPL_ENDOFNAMES);
HANDLER(handle_RPL_ENDOFMOTD);
HANDLER(handle_ERR_NICKNAMEINUSE);
+HANDLER(handle_RPL_AWAY);
#undef HANDLER
struct Handler handlers[] = {
@@ -62,6 +63,7 @@ struct Handler handlers[] = {
{ "NOTICE", handle_PRIVMSG },
{ "001", handle_RPL_WELCOME },
{ "005", handle_RPL_ISUPPORT },
+ { "301", handle_RPL_AWAY },
{ "324", handle_RPL_CHANNELMODEIS },
{ "331", handle_RPL_NOTOPIC },
{ "329", NULL }, /* ignore this:
@@ -315,6 +317,18 @@ handle_RPL_ISUPPORT(struct Server *server, struct History *msg) {
}
static void
+handle_RPL_AWAY(struct Server *server, struct History *msg) {
+ struct Channel *priv;
+ struct HistInfo *history;
+
+ if ((priv = chan_get(&server->privs, *(msg->params+2), -1)) != NULL)
+ history = priv->history;
+ else
+ history = server->history;
+ hist_addp(history, msg, Activity_status, HIST_DFL);
+}
+
+static void
handle_RPL_CHANNELMODEIS(struct Server *server, struct History *msg) {
struct Channel *chan;
diff --git a/src/ui.c b/src/ui.c
@@ -1512,9 +1512,8 @@ ui_format(struct Window *window, char *format, struct History *hist) {
if (escape && *format == 'n') {
ret[rc++] = '\n';
- snprintf(printformat, sizeof(printformat), "%%%lds%%s",
+ rc += snprintf(&ret[rc], sizeof(ret) - rc, "%1$*3$s%2$s", "", config_gets("divider.string"),
ui_strlenc(NULL, ts, NULL) + config_getl("divider.margin"));
- rc += snprintf(&ret[rc], sizeof(ret) - rc, printformat, "", config_gets("divider.string"));
escape = 0;
format++;
continue;