irctk

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

commit bea07f7af5f9bd972832f23c4ce9cdd3160c5936
parent 7c17237005a9c49eb91c4815ed9bca88768e3c51
Author: Antoine Amarilli <a3nm@a3nm.net>
Date:   Wed, 11 Jul 2012 22:12:54 +0200

auto-join

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

diff --git a/irctk.c b/irctk.c @@ -74,8 +74,11 @@ static struct argp_option options[] = { {"retry-factor", 'Y', "secs", 0, "Retry delay multiplication factor after each failed attempt (default: 2)", MISC}, - /*{"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 }, // TODO*/ + {"auto-join", 'j', 0, 0, + "Automatically join and re-join channels as needed (default)", MISC }, + {"no-auto-join", 'J', 0, 0, + "Don't join other channels than those specified on the command-line, don't" + " re-join", MISC }, /*{"synchronous", 's', 0, 0, "Will wait for a multiline, blankline-terminated answer on stdin to all lines passed on stdout, and will bufferize activity before that", COM_MODE }, // TODO*/ @@ -191,6 +194,7 @@ struct arguments enum event_tos event_to; enum track track; + int join; char *username; int username_set; // to get nick as default username @@ -240,6 +244,7 @@ void initialize_args() args.event_to = NOTHING; args.track = NO; + args.join = 1; args.username_set = 0; args.username = args.nick; @@ -328,6 +333,12 @@ static error_t parse_opt (int key, char *arg, struct argp_state *state) arguments->filter = 1; arguments->prune = 1; break; + case 'J': + arguments->join = 0; + break; + case 'j': + arguments->join = 1; + break; case 'T': arguments->track = NO; break; @@ -1094,29 +1105,29 @@ int do_cmd_msg(irc_session_t *s, char* chan, char* line) /* TODO2 find a way to get real host name (part after !) */ /* TODO2 only join channels we haven't joined yet */ - join_channel(s, chan); + if (args.join) + join_channel(s, chan); /* TODO2 provide a means to escape '/' */ if (line[0] == '/' && args.command_to_event) { char *arg; - if ((arg = MATCH_CMD(line, "nick"))) - { + if ((arg = MATCH_CMD(line, "nick"))) { rsl = irc_cmd_nick (s, arg); } else if ((arg = MATCH_CMD0(line, "part"))) { - if (!*arg || *arg == '\n') - { + if (!*arg || *arg == '\n') { rsl = irc_cmd_part(s, chan); } else if (*arg == ' ') { rsl = irc_cmd_part(s, arg); } } else if ((arg = MATCH_CMD0(line, "join"))) { - if (!*arg || *arg == '\n') - { - debug("join %s", chan); - rsl = join_channel(s, chan); - } else if (*arg == ' ') { - debug("join %s", arg); - rsl = join_channel(s, arg); + if (args.join) { + if (!*arg || *arg == '\n') { + debug("join %s", chan); + rsl = join_channel(s, chan); + } else if (*arg == ' ') { + debug("join %s", arg); + rsl = join_channel(s, arg); + } } } else if ((arg = MATCH_CMD(line, "topic"))) { debug("topic %s", arg);