Add /ops command

It's pretty awkward with large channels since NAMES isn't sorted by
prefixes or anything... But having it accumulate names across many
replies would require more reworking.
weechat-hashes
C. McEnroe 2020-09-30 17:52:39 -04:00
parent dce6c11cf6
commit 3e67bf6557
4 changed files with 21 additions and 5 deletions

View File

@ -1,4 +1,4 @@
.Dd September 6, 2020
.Dd September 30, 2020
.Dt CATGIRL 1
.Os
.
@ -292,6 +292,8 @@ Change nicknames.
Send a notice.
.It Ic /ns Ar command
Send a command to NickServ.
.It Ic /ops
List channel operators.
.It Ic /part Op Ar message
Leave the channel.
.It Ic /query Ar nick

1
chat.h
View File

@ -246,6 +246,7 @@ extern struct Replies {
uint list;
uint mode;
uint names;
uint ops;
uint topic;
uint whois;
} replies;

View File

@ -174,6 +174,12 @@ static void commandNames(uint id, char *params) {
replies.names++;
}
static void commandOps(uint id, char *params) {
(void)params;
ircFormat("NAMES %s\r\n", idNames[id]);
replies.ops++;
}
static void commandInvite(uint id, char *params) {
if (!params) return;
char *nick = strsep(&params, " ");
@ -468,6 +474,7 @@ static const struct Handler {
{ "/o", commandOpen, Restricted },
{ "/op", commandOp, 0 },
{ "/open", commandOpen, Restricted },
{ "/ops", commandOps, 0 },
{ "/part", commandPart, 0 },
{ "/query", commandQuery, Restricted },
{ "/quit", commandQuit, 0 },

View File

@ -499,20 +499,26 @@ static void handleReplyNames(struct Message *msg) {
char *user = strsep(&name, "@");
enum Color color = (user ? hash(user) : Default);
completeAdd(id, nick, color);
if (!replies.names) continue;
if (replies.ops && (prefixes == nick || prefixes[0] == '+')) continue;
if (!replies.ops && !replies.names) continue;
catf(&cat, "%s\3%02d%s\3", (buf[0] ? ", " : ""), color, prefixes);
}
if (!replies.names) return;
if (!cat.len) return;
uiFormat(
id, Cold, tagTime(msg),
"In \3%02d%s\3 are %s",
"%s \3%02d%s\3 are %s",
(replies.ops ? "The operators of" : "In"),
hash(msg->params[2]), msg->params[2], buf
);
}
static void handleReplyEndOfNames(struct Message *msg) {
(void)msg;
if (replies.names) replies.names--;
if (replies.ops) {
replies.ops--;
} else if (replies.names) {
replies.names--;
}
}
static void handleReplyNoTopic(struct Message *msg) {