Generate /ops from cache

weechat-hashes
June McEnroe 2022-09-11 17:34:41 -04:00
parent d043bad63d
commit fcbe7af1e2
3 changed files with 38 additions and 8 deletions

13
chat.h
View File

@ -168,6 +168,19 @@ extern struct Network {
char invex; char invex;
} network; } network;
static inline uint prefixBit(char p) {
char *s = strchr(network.prefixes, p);
if (!s) return 0;
return 1 << (s - network.prefixes);
}
static inline char bitPrefix(uint p) {
for (uint i = 0; network.prefixes[i]; ++i) {
if (p & (1 << i)) return network.prefixes[i];
}
return '\0';
}
#define ENUM_CAP \ #define ENUM_CAP \
X("causal.agency/consumer", CapConsumer) \ X("causal.agency/consumer", CapConsumer) \
X("chghost", CapChghost) \ X("chghost", CapChghost) \

View File

@ -219,8 +219,31 @@ static void commandNames(uint id, char *params) {
static void commandOps(uint id, char *params) { static void commandOps(uint id, char *params) {
(void)params; (void)params;
ircFormat("WHO %s\r\n", idNames[id]); char buf[1024];
replies[ReplyWho]++; char *ptr = buf, *end = &buf[sizeof(buf)];
ptr = seprintf(
ptr, end, "The council of \3%02d%s\3 are ",
idColors[id], idNames[id]
);
bool first = true;
struct Cursor curs = {0};
for (const char *nick; (nick = cacheNextKey(&curs, id));) {
char prefix = bitPrefix(curs.entry->prefixBits);
if (!prefix || prefix == '+') continue;
ptr = seprintf(
ptr, end, "%s\3%02d%c%s\3",
(first ? "" : ", "), curs.entry->color, prefix, nick
);
first = false;
}
if (first) {
uiFormat(
id, Warm, NULL, "\3%02d%s\3 is a lawless wasteland",
idColors[id], idNames[id]
);
} else {
uiWrite(id, Warm, NULL, buf);
}
} }
static void commandInvite(uint id, char *params) { static void commandInvite(uint id, char *params) {

View File

@ -560,12 +560,6 @@ static void handleErrorUserOnChannel(struct Message *msg) {
); );
} }
static uint prefixBit(char p) {
char *s = strchr(network.prefixes, p);
if (!s) return 0;
return 1 << (s - network.prefixes);
}
static void handleReplyNames(struct Message *msg) { static void handleReplyNames(struct Message *msg) {
require(msg, false, 4); require(msg, false, 4);
uint id = idFor(msg->params[2]); uint id = idFor(msg->params[2]);