Handle NICK
parent
0705f09310
commit
58e1d5b4e2
2
chat.h
2
chat.h
|
@ -151,8 +151,10 @@ char *editTail(void);
|
||||||
const char *complete(size_t id, const char *prefix);
|
const char *complete(size_t id, const char *prefix);
|
||||||
void completeAccept(void);
|
void completeAccept(void);
|
||||||
void completeReject(void);
|
void completeReject(void);
|
||||||
|
size_t completeID(const char *str);
|
||||||
void completeAdd(size_t id, const char *str, enum Color color);
|
void completeAdd(size_t id, const char *str, enum Color color);
|
||||||
void completeTouch(size_t id, const char *str, enum Color color);
|
void completeTouch(size_t id, const char *str, enum Color color);
|
||||||
|
void completeReplace(size_t id, const char *old, const char *new);
|
||||||
void completeRemove(size_t id, const char *str);
|
void completeRemove(size_t id, const char *str);
|
||||||
void completeClear(size_t id);
|
void completeClear(size_t id);
|
||||||
|
|
||||||
|
|
21
complete.c
21
complete.c
|
@ -110,6 +110,27 @@ void completeReject(void) {
|
||||||
match = NULL;
|
match = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t completeID(const char *str) {
|
||||||
|
for (match = (match ? match->next : head); match; match = match->next) {
|
||||||
|
if (match->id && !strcmp(match->str, str)) return match->id;
|
||||||
|
}
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
|
||||||
|
void completeReplace(size_t id, const char *old, const char *new) {
|
||||||
|
struct Node *next = NULL;
|
||||||
|
for (struct Node *node = head; node; node = node->next) {
|
||||||
|
next = node->next;
|
||||||
|
if (id && node->id != id) continue;
|
||||||
|
if (strcmp(node->str, old)) continue;
|
||||||
|
if (match == node) match = NULL;
|
||||||
|
free(node->str);
|
||||||
|
node->str = strdup(new);
|
||||||
|
if (!node->str) err(EX_OSERR, "strdup");
|
||||||
|
prepend(detach(node));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void completeRemove(size_t id, const char *str) {
|
void completeRemove(size_t id, const char *str) {
|
||||||
struct Node *next = NULL;
|
struct Node *next = NULL;
|
||||||
for (struct Node *node = head; node; node = next) {
|
for (struct Node *node = head; node; node = next) {
|
||||||
|
|
17
handle.c
17
handle.c
|
@ -261,6 +261,22 @@ static void handleTopic(struct Message *msg) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void handleNick(struct Message *msg) {
|
||||||
|
require(msg, true, 1);
|
||||||
|
if (self.nick && !strcmp(msg->nick, self.nick)) {
|
||||||
|
set(&self.nick, msg->params[0]);
|
||||||
|
}
|
||||||
|
size_t id;
|
||||||
|
completeReplace(None, msg->nick, msg->params[0]);
|
||||||
|
while (None != (id = completeID(msg->params[0]))) {
|
||||||
|
uiFormat(
|
||||||
|
id, Cold, tagTime(msg),
|
||||||
|
"\3%02d%s\3\tis now known as \3%02d%s\3",
|
||||||
|
hash(msg->user), msg->nick, hash(msg->user), msg->params[0]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static bool isAction(struct Message *msg) {
|
static bool isAction(struct Message *msg) {
|
||||||
if (strncmp(msg->params[1], "\1ACTION ", 8)) return false;
|
if (strncmp(msg->params[1], "\1ACTION ", 8)) return false;
|
||||||
msg->params[1] += 8;
|
msg->params[1] += 8;
|
||||||
|
@ -354,6 +370,7 @@ static const struct Handler {
|
||||||
{ "CAP", handleCap },
|
{ "CAP", handleCap },
|
||||||
{ "ERROR", handleError },
|
{ "ERROR", handleError },
|
||||||
{ "JOIN", handleJoin },
|
{ "JOIN", handleJoin },
|
||||||
|
{ "NICK", handleNick },
|
||||||
{ "NOTICE", handlePrivmsg },
|
{ "NOTICE", handlePrivmsg },
|
||||||
{ "PART", handlePart },
|
{ "PART", handlePart },
|
||||||
{ "PING", handlePing },
|
{ "PING", handlePing },
|
||||||
|
|
Loading…
Reference in New Issue