irctk

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

commit fc567a03babbed35176d38c92010076b82ba186b
parent 4f41cce703d0c934c6f61aa10a59dcdbab292bfb
Author: Antoine Amarilli <ant.amarilli@free.fr>
Date:   Sun, 16 Jan 2011 02:07:35 +0100

done intelligent channel routing which in fact could never have worked
as intended cause father christmas doesn't exist

Diffstat:
irctk.c | 63++++++++++++++++++++++++++++++++++++++++++++++++++++++---------
1 file changed, 54 insertions(+), 9 deletions(-)

diff --git a/irctk.c b/irctk.c @@ -25,6 +25,7 @@ * $Id: irctest.c 73 2009-01-03 11:14:59Z gyunaev $ */ +/* TODO detect if stdin is a tty for delay configuration */ /* TODO interpret '/' commands or not * TODO do interpret [] prefix * TODO default is to last chan till whitespace (or give whitespace to @@ -51,6 +52,9 @@ #define E_CONNECT 2 #define E_THREAD 3 +// TODO +#define MAX_LEN 1024 + const char *argp_program_version = "irctk 0.1"; const char *argp_program_bug_address = "<a3nm@a3nm.net>"; @@ -81,6 +85,10 @@ static struct argp_option options[] = { "Wait delay between posted messages (default: 1)" }, {"always-first", 'f', 0, 0, "Always post messages as-is to the first specified channel (default is to post to the last active channel, reseting on blank lines: bot scripts should put a blank line before and after messages)" }, /* TODO oh, and on leading blankline, display the channel name on stderr, for the client, that would be so cool!! */ + /* option to not use a newline to end (ie. reply immediately one-line + * messages */ + /* TODO because you can't get a pony, add support for exec of sth at + * each line (ie. spawn a thread) */ { 0 } }; @@ -100,6 +108,8 @@ struct arguments int own; char * raw_dest; char ready; + char memo_chan[MAX_LEN]; + char last_chan[MAX_LEN]; // <- TODO last pseudo, for custom resp to pseudo }; @@ -358,6 +368,13 @@ void event_channel (irc_session_t * session, const char * event, const char * or printf("> %s\n", params[1] ); if ( !origin ) return; + if (!args.memo_chan[0]) + { + debug("memorize last chan to %s", params[0]); + strcpy(args.last_chan, params[0]); + } + + fflush(stdout); /*irc_target_get_nick (origin, nickbuf, sizeof(nickbuf)); @@ -499,7 +516,7 @@ int start () // TODO manage duplicate pseudos sleep(1); } - debug("got %s"); + debug("got %s", line); if (line[0] == '[' && line[1] != ']') { @@ -535,16 +552,36 @@ int start () } else { /* No target specified, we attempt the default */ /* TODO WRITE BETTER DEFAULT */ - if (line[0] == '[') - line += 2; // we start with '[]' - if (args.n_channels) + if (line [0] == '\n' && args.memo_chan[0]) { - if ( irc_cmd_msg (s, args.channels[0], line) ) + /* TODO we should have posted, check that! */ + debug("unfix chan which was at %s", args.memo_chan); + args.memo_chan[0] = 0; + } else { + debug("trying to post, last is %s and memo is %s", args.last_chan, args.memo_chan); + if (!args.memo_chan[0]) + { + debug("fix chan to %s", args.last_chan); + strcpy(args.memo_chan, args.last_chan); + } + debug("update trying to post, last is %s and memo is %s", args.last_chan, args.memo_chan); + if (line[0] == '[') + line += 2; // we start with '[]' + /* + if (args.n_channels) + { + if ( irc_cmd_msg (s, args.channels[0], line) ) + break; + if (args.own) // TODO ask the server to notify? or at least refactor and get the real pseudo with '!' and chan etc + printf("[%s] <%s> %s", args.channels[0], args.nick, line); + } + else debug("No channel to send to!"); + */ + if ( irc_cmd_msg (s, args.memo_chan, line) ) break; - if (args.own) /* TODO ask the server to notify? or at least refactor and get the real pseudo with '!' and chan etc.*/ - printf("[%s] <%s> %s", args.channels[0], args.nick, line); + if (args.own) // TODO ask the server to notify? or at least refactor and get the real pseudo with '!' and chan etc + printf("[%s] <%s> %s", args.memo_chan, args.nick, line); } - else debug("No channel to send to!"); } sleep(args.interval); @@ -569,11 +606,19 @@ int main (int argc, char **argv) args.own = 0; args.nick = "irctk"; args.port = 6667; + args.memo_chan[0] = 0; + args.last_chan[0] = 0; /* Parse our arguments; every option seen by parse_opt will be reflected in arguments. */ argp_parse (&argp, argc, argv, 0, 0, &args); - + + if (args.n_channels) + { + strcpy(args.last_chan, args.nick); + } else { + strcpy(args.last_chan, args.channels[0]); + } if(args.verbose) { fprintf (stderr, "n_channels = %d\ninterval = %d\nnick = %s\nserver = %s\nport = %d\n",