irctk

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

commit 64925934febf7d6d2049e79e89ba5e58b3310a6e
parent 114d6ed8a07b93318835cb550666f711997a9f53
Author: Antoine Amarilli <ant.amarilli@free.fr>
Date:   Sun, 16 Jan 2011 18:52:17 +0100

done -F and -f

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

diff --git a/irctk.c b/irctk.c @@ -108,7 +108,7 @@ static struct argp_option options[] = { /* TODO should not delay for bots, only for things piped, is there a * better way such as only waiting at the end? */ MISC}, - {"default-always-first", 'f', 0, 0, + {"default-always-first", '0', 0, 0, "Post messages to the first specified channel by default", CHANNEL_SELECTION}, {"default-last-active", 'a', 0, 0, @@ -130,8 +130,10 @@ 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 }, + {"filter-prune", 'F', 0, 0, + "Only give the message body without the channel, nick or address (useful with -fr)", 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 }, { 0 } @@ -162,6 +164,7 @@ struct arguments int show_nick_prefix; int with_host; int filter; + int prune; }; typedef struct arguments irc_ctx_t; @@ -205,6 +208,8 @@ void initialize_args() args.verbosity = 0; args.with_host = 0; + args.filter = 0; + args.prune = 0; debug("coucou1"); debug_args(); // TODO this is debug args.n_channels = 0; @@ -360,11 +365,15 @@ parse_opt (int key, char *arg, struct argp_state *state) case 'r': arguments->show_nick_prefix = 1; break; - case 'f': + case '0': arguments->default_destination = DEFAULT_FIRST; break; + case 'f': + arguments->filter = 1; + break; case 'F': arguments->filter = 1; + arguments->prune = 1; break; case 'a': arguments->default_destination = DEFAULT_LAST_IN; @@ -567,7 +576,8 @@ void event_channel (irc_session_t * session, const char * event, const char * or //char nickbuf[128]; int i=0; - int ok = 1; + int ok = 1, ok2; + char* pruned; if ( count != 2 ) return; @@ -582,21 +592,41 @@ void event_channel (irc_session_t * session, const char * event, const char * or 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"); - + if (!args.prune) + { + 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"); + } else { + pruned = params[1]; + ok2 = 1; + while(pruned[0] != ':') + { + if (!pruned[0] || pruned[0] == ' ') + { + ok2 = 0; + break; + } + pruned++; + } + + if (ok2) + pruned += 2; // skip the punctuation (TODO better) + else pruned = params[1]; // no address + + printf("%s\n", pruned); + } fflush(stdout); }