Rewrite mode formatting again and write to log

Going back to one line per mode change again because it's easier.
weechat-hashes
C. McEnroe 2020-03-28 12:08:10 -04:00
parent 3dc998272e
commit bb2f3c7a01
1 changed files with 101 additions and 65 deletions

166
handle.c
View File

@ -575,16 +575,16 @@ static void handleReplyUserModeIs(struct Message *msg) {
char buf[1024] = ""; char buf[1024] = "";
for (char *ch = msg->params[1]; *ch; ++ch) { for (char *ch = msg->params[1]; *ch; ++ch) {
if (*ch == '+') continue; if (*ch == '+') continue;
if (UserModes[(byte)*ch]) { const char *name = UserModes[(byte)*ch];
catf(buf, sizeof(buf), ", %s", UserModes[(byte)*ch]); catf(
} else { buf, sizeof(buf), ", +%c%s%s",
catf(buf, sizeof(buf), ", +%c", *ch); *ch, (name ? " " : ""), (name ? name : "")
} );
} }
uiFormat( uiFormat(
Network, Warm, tagTime(msg), Network, Warm, tagTime(msg),
"\3%02d%s\3\tis %s", "\3%02d%s\3\tis %s",
self.color, self.nick, (buf[0] ? &buf[2] : buf) self.color, self.nick, (buf[0] ? &buf[2] : "modeless")
); );
} }
@ -613,25 +613,28 @@ static void handleReplyChannelModeIs(struct Message *msg) {
for (char *ch = msg->params[2]; *ch; ++ch) { for (char *ch = msg->params[2]; *ch; ++ch) {
if (*ch == '+') continue; if (*ch == '+') continue;
const char *name = ChanModes[(byte)*ch]; const char *name = ChanModes[(byte)*ch];
if (!name) name = (const char[]) { '+', *ch, '\0' };
if ( if (
strchr(network.paramModes, *ch) || strchr(network.paramModes, *ch) ||
strchr(network.setParamModes, *ch) strchr(network.setParamModes, *ch)
) { ) {
assert(param < ParamCap); assert(param < ParamCap);
catf( catf(
buf, sizeof(buf), ", has %s of %s", buf, sizeof(buf), ", +%c%s%s %s",
name, msg->params[param++] *ch, (name ? " " : ""), (name ? name : ""),
msg->params[param++]
); );
} else { } else {
catf(buf, sizeof(buf), ", is %s", name); catf(
buf, sizeof(buf), ", +%c%s%s",
*ch, (name ? " " : ""), (name ? name : "")
);
} }
} }
uiFormat( uiFormat(
idFor(msg->params[1]), Cold, tagTime(msg), idFor(msg->params[1]), Cold, tagTime(msg),
"\3%02d%s\3\t%s", "\3%02d%s\3\tis %s",
hash(msg->params[1]), msg->params[1], hash(msg->params[1]), msg->params[1],
(buf[0] ? &buf[2] : "has no modes") (buf[0] ? &buf[2] : "modeless")
); );
} }
@ -640,109 +643,142 @@ static void handleMode(struct Message *msg) {
if (!strchr(network.chanTypes, msg->params[0][0])) { if (!strchr(network.chanTypes, msg->params[0][0])) {
bool set = true; bool set = true;
char buf[1024] = "";
for (char *ch = msg->params[1]; *ch; ++ch) { for (char *ch = msg->params[1]; *ch; ++ch) {
if (*ch == '+') { set = true; continue; } if (*ch == '+') { set = true; continue; }
if (*ch == '-') { set = false; continue; } if (*ch == '-') { set = false; continue; }
const char *name = UserModes[(byte)*ch]; const char *name = UserModes[(byte)*ch];
if (!name) name = (const char[]) { "-+"[set], *ch, '\0' }; uiFormat(
catf( Network, Warm, tagTime(msg),
buf, sizeof(buf), ", %ssets \3%02d%s\3 %s", "\3%02d%s\3\t%ssets \3%02d%s\3 %c%c%s%s",
(set ? "" : "un"), self.color, msg->params[0], name hash(msg->user), msg->nick,
(set ? "" : "un"),
self.color, msg->params[0],
set["-+"], *ch, (name ? " " : ""), (name ? name : "")
); );
} }
if (!buf[0]) return;
uiFormat(
Network, Warm, tagTime(msg),
"\3%02d%s\3\t%s", hash(msg->user), msg->nick, &buf[2]
);
return; return;
} }
uint id = idFor(msg->params[0]); uint id = idFor(msg->params[0]);
bool set = true; bool set = true;
uint param = 2; uint i = 2;
char buf[1024] = "";
for (char *ch = msg->params[1]; *ch; ++ch) { for (char *ch = msg->params[1]; *ch; ++ch) {
if (*ch == '+') { set = true; continue; } if (*ch == '+') { set = true; continue; }
if (*ch == '-') { set = false; continue; } if (*ch == '-') { set = false; continue; }
const char *verb = (set ? "sets" : "unsets");
const char *name = ChanModes[(byte)*ch]; const char *name = ChanModes[(byte)*ch];
if (*ch == network.excepts) name = "except"; if (*ch == network.excepts) name = "except";
if (*ch == network.invex) name = "invite"; if (*ch == network.invex) name = "invite";
if (!name) name = (const char[]) { "-+"[set], *ch, '\0' }; const char *mode = (const char[]) {
set["-+"], *ch, (name ? ' ' : '\0'), '\0'
};
if (!name) name = "";
if (strchr(network.prefixModes, *ch)) { if (strchr(network.prefixModes, *ch)) {
assert(param < ParamCap); assert(i < ParamCap);
char *nick = msg->params[param++]; char *nick = msg->params[i++];
char prefix = network.prefixes[ char prefix = network.prefixes[
strchr(network.prefixModes, *ch) - network.prefixModes strchr(network.prefixModes, *ch) - network.prefixModes
]; ];
catf( uiFormat(
buf, sizeof(buf), ", %s \3%02d%c%s\3 \3%02d%s\3 %s", id, Cold, tagTime(msg),
(set ? "grants" : "revokes"), "\3%02d%s\3\t%s \3%02d%c%s\3 %s%s in \3%02d%s\3",
hash(msg->user), msg->nick, verb,
completeColor(id, nick), prefix, nick, completeColor(id, nick), prefix, nick,
hash(msg->params[0]), msg->params[0], mode, name, hash(msg->params[0]), msg->params[0]
name );
logFormat(
id, tagTime(msg), "%s %s %c%s %s%s in %s",
msg->nick, verb, prefix, nick, mode, name, msg->params[0]
); );
} }
if (strchr(network.listModes, *ch)) { if (strchr(network.listModes, *ch)) {
assert(param < ParamCap); assert(i < ParamCap);
char *mask = msg->params[param++]; char *mask = msg->params[i++];
if (*ch == 'b') { if (*ch == 'b') {
catf( verb = (set ? "bans" : "unbans");
buf, sizeof(buf), ", %sbans %s from \3%02d%s\3", uiFormat(
(set ? "" : "un"), mask, id, Cold, tagTime(msg),
"\3%02d%s\3\t%s %c%c %s from \3%02d%s\3",
hash(msg->user), msg->nick, verb, set["-+"], *ch, mask,
hash(msg->params[0]), msg->params[0] hash(msg->params[0]), msg->params[0]
); );
logFormat(
id, tagTime(msg), "%s %s %c%c %s from %s",
msg->nick, verb, set["-+"], *ch, mask, msg->params[0]
);
} else { } else {
catf( verb = (set ? "adds" : "removes");
buf, sizeof(buf), ", %s %s %s the \3%02d%s\3 %s list", const char *to = (set ? "to" : "from");
(set ? "adds" : "removes"), mask, (set ? "to" : "from"), uiFormat(
hash(msg->params[0]), msg->params[0], name id, Cold, tagTime(msg),
"\3%02d%s\3\t%s %s %s the \3%02d%s\3 %s%s list",
hash(msg->user), msg->nick, verb, mask, to,
hash(msg->params[0]), msg->params[0], mode, name
);
logFormat(
id, tagTime(msg), "%s %s %s %s the %s %s%s list",
msg->nick, verb, mask, to, msg->params[0], mode, name
); );
} }
} }
if (strchr(network.paramModes, *ch)) { if (strchr(network.paramModes, *ch)) {
assert(param < ParamCap); assert(i < ParamCap);
catf( char *param = msg->params[i++];
buf, sizeof(buf), ", %ssets \3%02d%s\3 %s %s %s", uiFormat(
(set ? "" : "un"), id, Cold, tagTime(msg),
hash(msg->params[0]), msg->params[0], name, "\3%02d%s\3\t%s \3%02d%s\3 %s%s %s",
(set ? "to" : "from"), msg->params[param++] hash(msg->user), msg->nick, verb,
hash(msg->params[0]), msg->params[0], mode, name, param
);
logFormat(
id, tagTime(msg), "%s %s %s %s%s %s",
msg->nick, verb, msg->params[0], mode, name, param
); );
} }
if (strchr(network.setParamModes, *ch) && set) { if (strchr(network.setParamModes, *ch) && set) {
assert(param < ParamCap); assert(i < ParamCap);
catf( char *param = msg->params[i++];
buf, sizeof(buf), ", sets \3%02d%s\3 %s to %s", uiFormat(
hash(msg->params[0]), msg->params[0], id, Cold, tagTime(msg),
name, msg->params[param++] "\3%02d%s\3\t%s \3%02d%s\3 %s%s %s",
hash(msg->user), msg->nick, verb,
hash(msg->params[0]), msg->params[0], mode, name, param
);
logFormat(
id, tagTime(msg), "%s %s %s %s%s %s",
msg->nick, verb, msg->params[0], mode, name, param
); );
} else if (strchr(network.setParamModes, *ch)) { } else if (strchr(network.setParamModes, *ch)) {
catf( uiFormat(
buf, sizeof(buf), ", unsets \3%02d%s\3 %s", id, Cold, tagTime(msg),
hash(msg->params[0]), msg->params[0], name "\3%02d%s\3\t%s \3%02d%s\3 %s%s",
hash(msg->user), msg->nick, verb,
hash(msg->params[0]), msg->params[0], mode, name
);
logFormat(
id, tagTime(msg), "%s %s %s %s%s",
msg->nick, verb, msg->params[0], mode, name
); );
} }
if (strchr(network.channelModes, *ch)) { if (strchr(network.channelModes, *ch)) {
catf( uiFormat(
buf, sizeof(buf), ", %ssets \3%02d%s\3 %s", id, Cold, tagTime(msg),
(set ? "" : "un"), hash(msg->params[0]), msg->params[0], name "\3%02d%s\3\t%s \3%02d%s\3 %s%s",
hash(msg->user), msg->nick, verb,
hash(msg->params[0]), msg->params[0], mode, name
);
logFormat(
id, tagTime(msg), "%s %s %s %s%s",
msg->nick, verb, msg->params[0], mode, name
); );
} }
} }
if (!buf[0]) return;
uiFormat(
id, Cold, tagTime(msg),
"\3%02d%s\3\t%s", hash(msg->user), msg->nick, &buf[2]
);
} }
static void handleErrorChanopPrivsNeeded(struct Message *msg) { static void handleErrorChanopPrivsNeeded(struct Message *msg) {