irctk

libircclient binding for scripts
git clone https://a3nm.net/git/irctk/
Log | Files | Refs | README

commit 636b0ae2790e1a5f657dfd900f78b42d02db7168
parent fe00a201ba0d03ac74eb45a0b3d2504f5f402111
Author: Antoine Amarilli <a3nm@a3nm.net>
Date:   Fri,  9 May 2014 18:11:51 +0200

add /notice command

Diffstat:
README | 1+
irctk.c | 35+++++++++++++++++++++++++++--------
2 files changed, 28 insertions(+), 8 deletions(-)

diff --git a/README b/README @@ -240,6 +240,7 @@ are: /me MSG (/me message) /say MSG (escape) / MSG (escape) + /notice MSG (like /say but use NOTICE) Optional channel names "[CHAN]" in the above list default to the current inferred destination (i.e., the last active channel by default). diff --git a/irctk.c b/irctk.c @@ -24,6 +24,8 @@ #define E_BADNAME 6 #define E_BADLINE 7 +enum do_say_type {DO_SAY_MSG, DO_SAY_NOTICE}; + enum default_destinations {DEFAULT_FIRST, DEFAULT_LAST_IN, DEFAULT_LAST_OUT, DEFAULT_ALL}; enum event_tos {NOTHING, COMMAND, MESSAGE}; enum track {NO, YES, UNIQUE}; @@ -1058,7 +1060,7 @@ int do_me(irc_session_t *s, char *chan, char *password, char *line) { return ret; } -int do_say(irc_session_t *s, char *chan, char *password, char *line) { +int do_say(irc_session_t *s, char *chan, char *password, char *line, enum do_say_type type) { /* TODO2 only join channels we haven't joined yet */ if (args.join && chan[0] == '#') irc_cmd_join(s, chan, password); @@ -1069,7 +1071,15 @@ int do_say(irc_session_t *s, char *chan, char *password, char *line) { line); } - return irc_cmd_msg(s, chan, line); + switch (type) { + case DO_SAY_MSG: + return irc_cmd_msg(s, chan, line); + + case DO_SAY_NOTICE: + return irc_cmd_notice(s, chan, line); + } + + abort(); // unreachable } /* If chan is suffixed by a password, modify it and return the modified offset */ @@ -1178,15 +1188,24 @@ int do_cmd_msg(irc_session_t *s, char *chan, char* line) } else if ((arg = MATCH_CMD0(line, "say"))) { // just a way to escape messages starting by '/' if (*arg == ' ') { - rsl = do_say(s, chan, password, arg + 1); + rsl = do_say(s, chan, password, arg + 1, DO_SAY_MSG); + } else if (!*arg || *arg == '\n') { + rsl = do_say(s, chan, password, arg, DO_SAY_MSG); + } else { + info("Unrecognized command: %s", line); + } + } else if ((arg = MATCH_CMD0(line, "notice"))) { + // same, but for notices + if (*arg == ' ') { + rsl = do_say(s, chan, password, arg + 1, DO_SAY_NOTICE); } else if (!*arg || *arg == '\n') { - rsl = do_say(s, chan, password, arg); + rsl = do_say(s, chan, password, arg, DO_SAY_NOTICE); } else { info("Unrecognized command: %s", line); } } else if (line[1] == ' ') { // another way, compatible with irssi: "/ /message" - rsl = do_say(s, chan, password, line + 2); + rsl = do_say(s, chan, password, line + 2, DO_SAY_MSG); } else { info("Unrecognized or malformed command: %s", line); } @@ -1211,7 +1230,7 @@ int do_cmd_msg(irc_session_t *s, char *chan, char* line) break; } if (seppos == -1) { - rsl = do_say(s, chan, password, line); + rsl = do_say(s, chan, password, line, DO_SAY_MSG); } else { char sep; sep = line[seppos]; @@ -1225,10 +1244,10 @@ int do_cmd_msg(irc_session_t *s, char *chan, char* line) pthread_mutex_unlock(&fifos.ctrl.mutex); line[seppos] = sep; strncat(lline, line + seppos, MAX_LINE_LEN-1); - rsl = do_say(s, chan, password, lline); + rsl = do_say(s, chan, password, lline, DO_SAY_MSG); } } else { - rsl = do_say(s, chan, password, line); + rsl = do_say(s, chan, password, line, DO_SAY_MSG); } }