diff options
author | ꦌ ꦫꦶ ꦏ꧀ꦦꦿ ꦧ ꦮ ꦑ ꦩ ꦭ꧀ <erik@darapsa.co.id> | 2019-12-31 15:53:46 +0800 |
---|---|---|
committer | ꦌ ꦫꦶ ꦏ꧀ꦦꦿ ꦧ ꦮ ꦑ ꦩ ꦭ꧀ <erik@darapsa.co.id> | 2019-12-31 15:53:46 +0800 |
commit | 7994cb472dc262dcb3e0e27519715dd176c6f8d6 (patch) | |
tree | c385876f94ebb3caebc2ff91e4d46678fac39dc8 /dircpsa.c |
A bot that joins a channel and post a message
The arguments to the executable are the channel and the message.
Diffstat (limited to 'dircpsa.c')
-rw-r--r-- | dircpsa.c | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/dircpsa.c b/dircpsa.c new file mode 100644 index 0000000..1bc40b6 --- /dev/null +++ b/dircpsa.c @@ -0,0 +1,60 @@ +#include <stdio.h> +#include <string.h> +#include <libircclient.h> + +typedef struct { + char *channel; + char *message; +} irc_ctx_t; + +void event_connect(irc_session_t *session, const char *event, const char *origin + , const char **params, unsigned int count) +{ + irc_ctx_t *ctx = (irc_ctx_t *)irc_get_ctx(session); + irc_cmd_join(session, ctx->channel, NULL); +} + +void event_join(irc_session_t *session, const char *event, const char *origin + , const char **params, unsigned int count) +{ + irc_ctx_t *ctx = (irc_ctx_t *)irc_get_ctx(session); + irc_cmd_user_mode(session, "+i"); + irc_cmd_msg(session, params[0], ctx->message); + irc_cmd_quit (session, "selesai"); +} + +int main (int argc, char *argv[]) +{ + if (argc != 3) { + printf("Usage: %s <channel> <message>\n", argv[0]); + return 1; + } + irc_ctx_t ctx = {.channel = argv[1], .message = argv[2]}; + + irc_callbacks_t callbacks; + memset(&callbacks, 0, sizeof(callbacks)); + callbacks.event_connect = event_connect; + callbacks.event_join = event_join; + + irc_session_t *session = irc_create_session(&callbacks); + if (!session) { + printf("Could not create session\n"); + return 1; + } + irc_set_ctx(session, &ctx); + + if (irc_connect(session, "irc.darapsa.co.id", 6667, 0, "git", "interch" + , "Darapsa")) { + printf("Could not connect: %s\n" + , irc_strerror(irc_errno(session))); + return 1; + } + + if (irc_run(session)) { + printf ("Could not connect or I/O error: %s\n" + , irc_strerror (irc_errno(session))); + return 1; + } + + return 1; +} |