irctk

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

commit 06bf2bb57ece6c5086a9ae3622bb4bb00566c3fa
parent 8bfc9b7f08c5fc3e00fdcec7c3ce034250a98adc
Author: Antoine Amarilli <ant.amarilli@free.fr>
Date:   Sun, 16 Jan 2011 14:01:02 +0100

-w and -r (fragile)

Diffstat:
irctk.c | 44+++++++++++++++++++++++++++++++++++++++-----
1 file changed, 39 insertions(+), 5 deletions(-)

diff --git a/irctk.c b/irctk.c @@ -56,7 +56,7 @@ #define DEFAULT_LAST_IN 1 #define DEFAULT_LAST_OUT 2 // TODO -#define MAX_LEN 1024 +#define MAX_LEN 4096 //const char *argp_program_version = "irctk 0.1"; //const char *argp_program_bug_address = "<a3nm@a3nm.net>"; @@ -129,7 +129,7 @@ static struct argp_option options[] = { "Run this command on each message, passing the channel, nick and message as $1, $2, and $3", COM_MODE }, /* TODO and allow to pipe on argv rather than stdin */ {"reply", 'r', 0, 0, - "When inferring a destination channel automatically, also infer a destination nick, and prefix lines with this nick", BOT_OPTIONS }, + "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, "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, @@ -155,9 +155,12 @@ struct arguments char * raw_dest; char ready; char last_chan_in[MAX_LEN]; + char last_nick_in[MAX_LEN]; char last_chans_out[MAX_LEN]; int default_destination; int show_prefix; + int show_nick_prefix; + int with_host; }; typedef struct arguments irc_ctx_t; @@ -200,6 +203,7 @@ void initialize_args() { args.verbosity = 0; + args.with_host = 0; debug("coucou1"); debug_args(); // TODO this is debug args.n_channels = 0; @@ -211,6 +215,7 @@ void initialize_args() args.nick = "irctk"; args.port = 6667; args.last_chan_in[0] = 0; + args.last_nick_in[0] = 0; args.last_chans_out[0] = 0; args.default_destination = DEFAULT_LAST_IN; args.show_prefix = 0; @@ -262,6 +267,7 @@ int cmd_msg(irc_session_t *s, char* target, const char* line) int cont = 1; char tmp; char *one_target; + char *msg[MAX_LEN]; /* TODO TODO TODO !! */ int rsl; /* Manage the fact that target may be "" */ @@ -275,6 +281,20 @@ int cmd_msg(irc_session_t *s, char* target, const char* line) case DEFAULT_LAST_IN: target = args.last_chan_in; + if (args.show_nick_prefix && args.last_nick_in[0]) + { + if (line[0] != '\n') + { + msg[0] = 0; + /*TODO USE strncat!! */ + strcat(msg, args.last_nick_in); + strcat(msg, ": "); + strcat(msg, line); + line = msg; + } else { + args.last_nick_in[0] = 0; + } + } break; case DEFAULT_LAST_OUT: @@ -333,6 +353,12 @@ parse_opt (int key, char *arg, struct argp_state *state) case 'o': arguments->own = 1; break; + case 'w': + arguments->with_host = 1; + break; + case 'r': + arguments->show_nick_prefix = 1; + break; case 'f': arguments->default_destination = DEFAULT_FIRST; break; @@ -544,12 +570,14 @@ void event_channel (irc_session_t * session, const char * event, const char * or if (!origin) printf("someone"); else - /* TODO not robust */ - while(origin[i++] != '!') putchar(origin[i-1]); + /* 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"); fflush(stdout); @@ -660,6 +688,9 @@ irc_session_t* do_connect() if (!s) die(E_SESSION, "Could not create session"); + + if (!args.with_host) + irc_option_set (s, LIBIRC_OPTION_STRIPNICKS); irc_set_ctx (s, &args); debug_args(); @@ -753,6 +784,9 @@ int start () debug("ready", line); + /* 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 */ + gettimeofday(&tp2, NULL); tp = 1000000*(tp2.tv_sec - tp1.tv_sec) + tp2.tv_usec - tp1.tv_usec; if (tp < args.interval && !first) @@ -796,7 +830,7 @@ int main (int argc, char **argv) debug_args(); argp_parse (&argp, argc, argv, 0, 0, &args); - + strcpy(args.last_chan_in, first_chan()); strcpy(args.last_chans_out, first_chan());