commit 3f1b26d8d7171f362d4f6753e8630bf717978c4f
parent 8dbb917b866c9e8962787d6af9eff49bed4620c5
Author: Claudio Alessi <smoppy@gmail.com>
Date: Sun, 23 Jul 2017 20:08:03 +0200
Add /topic command.
Diffstat:
M | circo.c | | | 71 | +++++++++++++++++++++++++++++++++++++++++++++++++---------------------- |
M | config.def.h | | | 5 | +++++ |
2 files changed, 54 insertions(+), 22 deletions(-)
diff --git a/circo.c b/circo.c
@@ -81,10 +81,11 @@ int bufl2o(char *buf, int len, int line);
int bufnl(char *buf, int len);
int bufpos(char *buf, int len, int *line, int *off);
void cleanup(void);
+void cmd_close(char *cmd, char *s);
void cmd_msg(char *cmd, char *s);
void cmd_quit(char *cmd, char *s);
-void cmd_close(char *cmd, char *s);
void cmd_server(char *cmd, char *s);
+void cmd_topic(char *cmd, char *s);
void cmdln_chldel(const Arg *arg);
void cmdln_chrdel(const Arg *arg);
void cmdln_clear(const Arg *arg);
@@ -205,26 +206,6 @@ cleanup(void) {
}
void
-cmd_msg(char *cmd, char *s) {
- char *to, *txt;
-
- if(!srv) {
- printb(sel, "You're offline.\n");
- return;
- }
- to = s;
- txt = skip(to, ' ');
- privmsg(to, txt);
-}
-
-void
-cmd_quit(char *cmd, char *s) {
- if(srv)
- sout("QUIT%s%s", s ? " :" : "", s ? s : "");
- running = 0;
-}
-
-void
cmd_close(char *cmd, char *s) {
Buffer *b;
@@ -248,6 +229,26 @@ cmd_close(char *cmd, char *s) {
}
void
+cmd_msg(char *cmd, char *s) {
+ char *to, *txt;
+
+ if(!srv) {
+ printb(sel, "You're offline.\n");
+ return;
+ }
+ to = s;
+ txt = skip(to, ' ');
+ privmsg(to, txt);
+}
+
+void
+cmd_quit(char *cmd, char *s) {
+ if(srv)
+ sout("QUIT%s%s", s ? " :" : "", s ? s : "");
+ running = 0;
+}
+
+void
cmd_server(char *cmd, char *s) {
char *h, *p;
@@ -275,6 +276,33 @@ cmd_server(char *cmd, char *s) {
}
void
+cmd_topic(char *cmd, char *s) {
+ char *chan, *txt;
+
+ if(!srv) {
+ printb(sel, "You're offline.\n");
+ return;
+ }
+ if(*s == '#' || *s == '&') {
+ chan = s;
+ txt = skip(s, ' ');
+ }
+ else {
+ if(sel == status) {
+ printb(sel, "Cannot set topic of the status.\n");
+ return;
+ }
+ chan = sel->name;
+ txt = s;
+ }
+ if(!*txt) {
+ printb(sel, "Usage: /%s [channel] text\n", cmd);
+ return;
+ }
+ sout("TOPIC %s :%s", chan, txt);
+}
+
+void
cmdln_chldel(const Arg *arg) {
if(!sel->cmdoff)
return;
@@ -604,7 +632,6 @@ parsesrv(void) {
txt = skip(par, ':');
trim(txt);
trim(par);
- //printb(status, "[DEBUG] %s | %s | %s | txt:(%s)\n", cmd, usr, par, txt);
if(!strcmp("PRIVMSG", cmd)) {
if(strcmp(nick, usr))
par = usr;
diff --git a/config.def.h b/config.def.h
@@ -1,11 +1,16 @@
/* See LICENSE file for copyright and license details. */
+/* Timestamp format; see strftime(3). */
+#define TIMESTAMP_FORMAT "%Y-%m-%d %T | "
+
Command commands[] = {
/* command function */
+ { "close", cmd_close },
{ "connect", cmd_server },
{ "msg", cmd_msg },
{ "quit", cmd_quit },
{ "server", cmd_server },
+ { "topic", cmd_topic },
};
/* key definitions */