Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // This is the calling function (event triggered when message is received in the channel.
- void event_channel (irc_session_t * session, const char * event, const char * origin, const char ** params, unsigned int count)
- {
- char nickbuf[128];
- irc_ctx_t * ctx = (irc_ctx_t *) irc_get_ctx (session);
- if ( count != 2 )
- return;
- printf ("'%s' said in channel %s: %s\n",
- origin ? origin : "someone",
- params[0], params[1] );
- if ( !origin )
- return;
- irc_target_get_nick (origin, nickbuf, sizeof(nickbuf));
- char isme[10];
- char isnick[15];
- char * args = '\0';
- strcpy(args, params[1] + 10);
- strncpy (isme, params[1], 4);
- strncpy (isnick, params[1] + 4, 5 );
- strcat(isnick, "\0");
- if ( !strcmp(isme, "!me ") )
- {
- if ( !strcmp (isnick, ctx->nick) )
- {
- if ( !strncmp(args, "quit", sizeof("quit") - 1) )
- {
- irc_cmd_quit (session, " Bye");
- }
- else if ( !strncmp(args, "help", sizeof("help") - 1) )
- {
- irc_cmd_msg (session, params[0], "quit, help");
- }
- else if ( strstr(args, "topic ") == args )
- {
- irc_cmd_topic (session, params[0], args + sizeof("topic ") -1);
- }
- else if ( strstr(args, "mode ") == args )
- {
- irc_cmd_channel_mode (session, params[0], args + sizeof("mode ") -1);
- }
- else if ( strstr(args, "nick ") == args )
- {
- irc_cmd_nick (session, args + sizeof("nick ") -1);
- }
- else if ( strstr(args, "cmd ") == args )
- {
- cmd(args);
- }
- else
- {
- irc_cmd_msg (session, params[0], "quit, help");
- }
- }
- }
- }
- // This is the function in question.
- void cmd(char * args)
- {
- char argsa[2][20];
- int i = 0;
- char splitargn[100];
- char *splitarg = splitargn;
- splitarg = strtok(args, " ");
- while ( splitarg != NULL )
- {
- strcpy(argsa[i],splitarg);
- splitarg = strtok(NULL, " ");
- printf(splitarg);
- i++;
- }
- }
- // Example calling command would me !me botnick cmd foo bar
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement