Only show expected topic/names replies

master
C. McEnroe 2020-02-08 03:15:17 -05:00
parent 2cacf15314
commit b6bf6d62b0
3 changed files with 35 additions and 1 deletions

5
chat.h
View File

@ -114,6 +114,11 @@ void ircSend(const char *ptr, size_t len);
void ircFormat(const char *format, ...)
__attribute__((format(printf, 1, 2)));
extern struct Replies {
size_t topic;
size_t names;
} replies;
void handle(struct Message msg);
void command(size_t id, char *input);
const char *commandIsPrivmsg(size_t id, const char *input);

View File

@ -71,7 +71,15 @@ static void commandMe(size_t id, char *params) {
}
static void commandJoin(size_t id, char *params) {
size_t count = 1;
if (params) {
for (char *ch = params; *ch && *ch != ' '; ++ch) {
if (*ch == ',') count++;
}
}
ircFormat("JOIN %s\r\n", (params ? params : idNames[id]));
replies.topic += count;
replies.names += count;
}
static void commandPart(size_t id, char *params) {

View File

@ -25,6 +25,8 @@
#include "chat.h"
struct Replies replies;
static const char *CapNames[] = {
#define X(name, id) [id##Bit] = name,
ENUM_CAP
@ -156,7 +158,15 @@ static void handleReplyWelcome(struct Message *msg) {
require(msg, false, 1);
set(&self.nick, msg->params[0]);
completeTouch(None, self.nick, Default);
if (self.join) ircFormat("JOIN %s\r\n", self.join);
if (self.join) {
size_t count = 1;
for (const char *ch = self.join; *ch && *ch != ' '; ++ch) {
if (*ch == ',') count++;
}
ircFormat("JOIN %s\r\n", self.join);
replies.topic += count;
replies.names += count;
}
}
static void handleReplyISupport(struct Message *msg) {
@ -278,6 +288,7 @@ static void handleQuit(struct Message *msg) {
static void handleReplyNames(struct Message *msg) {
require(msg, false, 4);
if (!replies.names) return;
size_t id = idFor(msg->params[2]);
char buf[1024];
size_t len = 0;
@ -302,8 +313,15 @@ static void handleReplyNames(struct Message *msg) {
);
}
static void handleReplyEndOfNames(struct Message *msg) {
(void)msg;
if (replies.names) replies.names--;
}
static void handleReplyNoTopic(struct Message *msg) {
require(msg, false, 2);
if (!replies.topic) return;
replies.topic--;
uiFormat(
idFor(msg->params[1]), Cold, tagTime(msg),
"There is no sign in \3%02d%s\3",
@ -313,6 +331,8 @@ static void handleReplyNoTopic(struct Message *msg) {
static void handleReplyTopic(struct Message *msg) {
require(msg, false, 3);
if (!replies.topic) return;
replies.topic--;
uiFormat(
idFor(msg->params[1]), Cold, tagTime(msg),
"The sign in \3%02d%s\3 reads: %s",
@ -421,6 +441,7 @@ static const struct Handler {
{ "331", handleReplyNoTopic },
{ "332", handleReplyTopic },
{ "353", handleReplyNames },
{ "366", handleReplyEndOfNames },
{ "372", handleReplyMOTD },
{ "432", handleErrorErroneousNickname },
{ "433", handleErrorNicknameInUse },