irctk

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

commit 114d6ed8a07b93318835cb550666f711997a9f53
parent 06bf2bb57ece6c5086a9ae3622bb4bb00566c3fa
Author: Antoine Amarilli <ant.amarilli@free.fr>
Date:   Sun, 16 Jan 2011 18:39:09 +0100

done filter

Diffstat:
irctk.c | 59++++++++++++++++++++++++++++++++++++++++-------------------
1 file changed, 40 insertions(+), 19 deletions(-)

diff --git a/irctk.c b/irctk.c @@ -130,7 +130,7 @@ static struct argp_option options[] = { /* TODO and allow to pipe on argv rather than stdin */ {"reply", 'r', 0, 0, "When inferring a destination channel automatically with --last-active, also infer a destination nick, and prefix lines with this nick (blank line terminates)", BOT_OPTIONS }, - {"filter", 'f', 0, 0, + {"filter", 'F', 0, 0, "Only keep messages directly addressed to us (in private channel or with lines prefixed by our nick)", BOT_OPTIONS }, {"no-auto-join", 0, 0, 0, "Refuse to send any message to channels not specified on the command line (default is to join as needed)", MISC }, @@ -161,6 +161,7 @@ struct arguments int show_prefix; int show_nick_prefix; int with_host; + int filter; }; typedef struct arguments irc_ctx_t; @@ -286,10 +287,10 @@ int cmd_msg(irc_session_t *s, char* target, const char* line) if (line[0] != '\n') { msg[0] = 0; - /*TODO USE strncat!! */ - strcat(msg, args.last_nick_in); + /*TODO USE strncat better!! */ + strncat(msg, args.last_nick_in, 1000); strcat(msg, ": "); - strcat(msg, line); + strncat(msg, line, 3000); line = msg; } else { args.last_nick_in[0] = 0; @@ -362,6 +363,9 @@ parse_opt (int key, char *arg, struct argp_state *state) case 'f': arguments->default_destination = DEFAULT_FIRST; break; + case 'F': + arguments->filter = 1; + break; case 'a': arguments->default_destination = DEFAULT_LAST_IN; break; @@ -496,8 +500,8 @@ void event_privmsg (irc_session_t * session, const char * event, const char * or { dump_event (session, event, origin, params, count); - /* TODO fill that in */ - printf("PRIVMSG"); + /* TODO sure? */ + event_channel (session, event, origin, params, count); } @@ -563,23 +567,38 @@ void event_channel (irc_session_t * session, const char * event, const char * or //char nickbuf[128]; int i=0; + int ok = 1; if ( count != 2 ) return; - printf ("[%s] <", params[0]); - if (!origin) - printf("someone"); - else - /* TODO not robust, and useless since we use STRIPNICKS */ - //while(origin[i++] != '!') putchar(origin[i-1]); - printf("%s", origin); - printf("> %s\n", params[1] ); - if ( !origin ) - return; - strcpy(args.last_chan_in, params[0]); - strcpy(args.last_nick_in, origin?origin:"someone"); + if (args.filter) + if (strcmp(params[0], args.nick)) + { + for (i=0; i<strlen(args.nick); i++) + if (args.nick[i] != params[1][i] || !params[1][i]) + ok = 0; + /* TODO test if ',' or ':' to avoid prefix nicks */ + } - fflush(stdout); + if (ok) + { + printf ("[%s] <", params[0]); + if (!origin) + printf("someone"); + else + /* TODO not robust, and useless since we use STRIPNICKS */ + //while(origin[i++] != '!') putchar(origin[i-1]); + printf("%s", origin); + printf("> %s\n", params[1] ); + if ( !origin ) + return; + if (strcmp(params[0], args.nick)) // if addressed in our private chan, reply on the sender's priv chan + strcpy(args.last_chan_in, params[0]); + else strcpy(args.last_chan_in, origin?origin:"someone"); + strcpy(args.last_nick_in, origin?origin:"someone"); + + fflush(stdout); + } /*irc_target_get_nick (origin, nickbuf, sizeof(nickbuf)); @@ -787,6 +806,8 @@ int start () /* TODO don't do that but a buffer of things to send, so we can save * to whom we are sending what despite the delays */ + /* TODO no wait on empty lines */ + gettimeofday(&tp2, NULL); tp = 1000000*(tp2.tv_sec - tp1.tv_sec) + tp2.tv_usec - tp1.tv_usec; if (tp < args.interval && !first)