Advertisement
Guest User

Untitled

a guest
Jul 5th, 2015
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1.  
  2. // This is the calling function (event triggered when message is received in the channel.
  3. void event_channel (irc_session_t * session, const char * event, const char * origin, const char ** params, unsigned int count)
  4. {
  5. char nickbuf[128];
  6. irc_ctx_t * ctx = (irc_ctx_t *) irc_get_ctx (session);
  7.  
  8. if ( count != 2 )
  9. return;
  10.  
  11. printf ("'%s' said in channel %s: %s\n",
  12. origin ? origin : "someone",
  13. params[0], params[1] );
  14.  
  15. if ( !origin )
  16. return;
  17.  
  18. irc_target_get_nick (origin, nickbuf, sizeof(nickbuf));
  19.  
  20. char isme[10];
  21. char isnick[15];
  22. char * args = '\0';
  23.  
  24. strcpy(args, params[1] + 10);
  25.  
  26. strncpy (isme, params[1], 4);
  27. strncpy (isnick, params[1] + 4, 5 );
  28. strcat(isnick, "\0");
  29.  
  30. if ( !strcmp(isme, "!me ") )
  31. {
  32. if ( !strcmp (isnick, ctx->nick) )
  33. {
  34. if ( !strncmp(args, "quit", sizeof("quit") - 1) )
  35. {
  36. irc_cmd_quit (session, " Bye");
  37. }
  38.  
  39. else if ( !strncmp(args, "help", sizeof("help") - 1) )
  40. {
  41. irc_cmd_msg (session, params[0], "quit, help");
  42. }
  43.  
  44. else if ( strstr(args, "topic ") == args )
  45. {
  46. irc_cmd_topic (session, params[0], args + sizeof("topic ") -1);
  47. }
  48.  
  49. else if ( strstr(args, "mode ") == args )
  50. {
  51. irc_cmd_channel_mode (session, params[0], args + sizeof("mode ") -1);
  52. }
  53. else if ( strstr(args, "nick ") == args )
  54. {
  55. irc_cmd_nick (session, args + sizeof("nick ") -1);
  56. }
  57.  
  58. else if ( strstr(args, "cmd ") == args )
  59. {
  60. cmd(args);
  61. }
  62. else
  63. {
  64. irc_cmd_msg (session, params[0], "quit, help");
  65. }
  66. }
  67. }
  68. }
  69.  
  70. // This is the function in question.
  71.  
  72. void cmd(char * args)
  73. {
  74. char argsa[2][20];
  75. int i = 0;
  76. char splitargn[100];
  77. char *splitarg = splitargn;
  78.  
  79.  
  80. splitarg = strtok(args, " ");
  81. while ( splitarg != NULL )
  82. {
  83. strcpy(argsa[i],splitarg);
  84. splitarg = strtok(NULL, " ");
  85. printf(splitarg);
  86. i++;
  87. }
  88. }
  89.  
  90. // Example calling command would me !me botnick cmd foo bar
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement