irctk

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

commit 0c62375e3f62420a2e488f2f7ce072ce6d88dd10
parent 7a12e3e6768f1d5aca26f923e34757d8eace20b7
Author: Antoine Amarilli <ant.amarilli@free.fr>
Date:   Thu, 17 Feb 2011 15:37:29 +0100

full name options, fixed bug, todos

Diffstat:
irctk.c | 34++++++++++++++++++++++++++--------
1 file changed, 26 insertions(+), 8 deletions(-)

diff --git a/irctk.c b/irctk.c @@ -45,7 +45,7 @@ // TODO pseudo tracking -// TODO customize full name, username... +// TODO default username is login pruned of bad chars //TODO const char *argp_program_version = "irctk 0.1"; //TODO const char *argp_program_bug_address = "<a3nm@a3nm.net>"; @@ -66,6 +66,7 @@ static char args_doc[] = "[NICK@]SERVER[:PORT] [CHANNEL]..."; #define BOT_OPTIONS 4 #define DISPLAY_SELECTION 5 #define PARSING 6 +#define NAME 7 /* The options we understand. */ static struct argp_option options[] = { @@ -81,17 +82,17 @@ static struct argp_option options[] = { PARSING}, // TODO */ {"event-to-nothing", 'n', 0, 0, "Ignore server events (default).", - PARSING}, // TODO + PARSING}, {"event-to-command", 'c', 0, 0, "Translate server events to messages with \"/quit\", \"/me\"...", - PARSING}, // TODO + PARSING}, {"event-to-message", 'm', 0, 0, "Translate server events to a human-readable description", - PARSING}, // TODO + PARSING}, {"with-host", 'w', 0, 0, "Keep the host info in pseudos" , DISPLAY_SELECTION}, - /* TODO make compatible with --own */ + /* TODO test, and make compatible with --own */ {"own", 'o', 0, 0, "Also display messages posted by self", DISPLAY_SELECTION}, @@ -99,7 +100,13 @@ static struct argp_option options[] = { "Wait delay between posted messages (default: 0 for tty stdin, 1 for file/pipe)", /* TODOponey ideally should not delay for bots, only for things piped, is there a * better way such as only waiting at the end? */ - MISC}, + MISC}, + {"username", 'U', "name", 0, + "Unix username (default: irctk)", + NAME}, + {"realname", 'R', "name", 0, + "Full name (default: irctk)", + NAME}, {"default-always-first", '0', 0, 0, "Post messages to the first specified channel by default", CHANNEL_SELECTION}, @@ -140,6 +147,8 @@ static struct argp_option options[] = { struct arguments { char *nick; + char *username; + char *realname; char *server; int port; char **channels; @@ -188,6 +197,8 @@ void initialize_args() args.default_destination = DEFAULT_LAST_IN; args.show_prefix = 0; args.event_to = NOTHING; + args.username = "irctk"; + args.realname = "irctk"; } @@ -220,6 +231,12 @@ static error_t parse_opt (int key, char *arg, struct argp_state *state) case 'i': arguments->interval = (int) (atof(arg) * 1000000.); break; + case 'U': + arguments->username = arg; + break; + case 'R': + arguments->realname = arg; + break; case 'o': arguments->own = 1; break; @@ -373,6 +390,7 @@ int do_cmd_msg(irc_session_t *s, const char* chan, const char* line) irc_cmd_join (s, chan, 0); + // TODO also other commands (/kick, /topic...) /* TODO2 provide a means to escape '/' */ if (line[0] == '/' && args.command_to_event) { if ( strstr (line + 1, "nick ") == line + 1 ) @@ -828,7 +846,7 @@ irc_session_t* do_connect() args.server, args.port, args.nick); - if (irc_connect (s, args.server, args.port, 0, args.nick, 0, 0)) + if (irc_connect (s, args.server, args.port, 0, args.nick, args.username, args.realname)) die(E_CONNECT, "Could not connect: %s\n", irc_strerror (irc_errno(s))); return s; @@ -871,7 +889,7 @@ int start () { waiting = 0; debug("Waiting for the connection to be ready..."); - while (waiting < max_wait) + while (waiting < max_wait && !args.ready) { debug("waiting"); // TODO manage timeouts, try reconnects, handle errors, etc.