Beispiel #1
0
int irc_parse_action(irc_t *irc) {
    // :msg_prefix msg_irc_command * :msg_command msg_suffix
    if (!(strchr(irc->servbuf, ' '))) {
    	return 0; // empty msg
    }
    irc_log_message(irc);
    char* ptr = strtok(irc->servbuf, " ");
    if (ptr != NULL && strncmp(ptr, "PING", 4) == 0) {
        return sck_sendf(irc->s, "PONG :%s\r\n", ptr);
    }
    ptr = strtok(NULL, " ");
    if (ptr != NULL && strncmp(ptr, "433", 3) == 0) {
    	irc_prepare(irc);
        return 0;
    }
    ptr = strtok(NULL, ":");
    ptr = strtok(NULL, " ");
    if (ptr != NULL && *ptr == '!') {
    	ptr++; // skips '!'
    	char msg_cmd[strlen(ptr)];
    	strncpy(msg_cmd, ptr, strlen(ptr));
    	ptr = strtok(NULL, "\0");
    	return irc_parse_uaction(irc, msg_cmd, ptr, count_args(ptr));
    }
    return 0;
}
Beispiel #2
0
// irc_msg: For sending a channel message or a query
int irc_msg(int s, const char *channel, const char *data)
{
   return sck_sendf(s, "PRIVMSG %s :%s\r\n", channel, data);
}
Beispiel #3
0
// irc_action: For executing an action (.e.g /me is hungry)
int irc_action(int s, const char *channel, const char *data)
{
   return sck_sendf(s, "PRIVMSG %s :\001ACTION %s\001\r\n", channel, data);
}
Beispiel #4
0
// irc_topic: For setting or removing a topic
int irc_topic(int s, const char *channel, const char *data)
{
   return sck_sendf(s, "TOPIC %s :%s\r\n", channel, data);
}
Beispiel #5
0
// irc_quit: For quitting IRC
int irc_quit(int s, const char *data)
{
   return sck_sendf(s, "QUIT :%s\r\n", data);
}
Beispiel #6
0
// irc_nick: For changing your nick
int irc_nick(int s, const char *data)
{
   return sck_sendf(s, "NICK %s\r\n", data);

}
Beispiel #7
0
// irc_part: For leaving a channel
int irc_part(int s, const char *data)
{
   return sck_sendf(s, "PART %s\r\n", data);

}
Beispiel #8
0
// irc_join: For joining a channel
int irc_join(int s, const char *data)
{
   return sck_sendf(s, "JOIN %s\r\n", data);

}
Beispiel #9
0
// irc_reg: For registering upon login
int irc_reg(int s, const char *nick, const char *username, const char *fullname)
{
   return sck_sendf(s, "NICK %s\r\nUSER %s localhost 0 :%s\r\n", nick, username, fullname);
}
Beispiel #10
0
// irc_pong: For answering pong requests...
int irc_pong(int s, const char *data)
{
   return sck_sendf(s, "PONG :%s\r\n", data);
}
Beispiel #11
0
void irc_prepare(irc_t* irc) {
    char* nick = gen_nick();
    sck_sendf(irc->s, "NICK %s\r\nUSER %s %s 0 :%s\r\n", nick, nick, nick, nick);
    free(nick);
    sck_sendf(irc->s, "JOIN %s\r\n", CHANNEL);
}
Beispiel #12
0
Datei: irc.c Projekt: tfryman/bot
int irc_reply_message(irc_t *irc, char *irc_nick, char *msg)
{
   // Checks if someone calls on the bot.
   if ( *msg != '!' )
      return 0;

   char *command;
   char *arg;
   // Gets command
   command = strtok(&msg[1], " ");
   arg = strtok(NULL, "");
   if ( arg != NULL )
      while ( *arg == ' ' )
         arg++;

   if ( command == NULL )
      return 0;

   if ( strcmp(command, "ping") == 0)
   {
      if ( irc_msg(irc->s, irc->channel, "pong") < 0)
         return -1;
   }
   else if ( strcmp(command, "war") == 0 )
   {
      if ( irc_msg(irc->s, irc->channel, "WMs again? gtfo.") < 0 )
         return -1;
   }
   
   else if ( strcmp(command, "nick") == 0 )
   {
      if ( arg != NULL && strlen(arg) > 0 )
         sck_sendf(irc->s, "NICK %s\r\n", arg);
         return -1;
   }
   else if ( strcmp(command, "smack") == 0 )
   {
      char mesg[512];
      srand(time(NULL));
      int critical;
      critical = (rand()%10)/8;
      
      if ( arg != NULL && strlen(arg) > 0 )
      {
         if ( critical )
            snprintf(mesg, 511, "I smack thee, %s, for %d damage (it's super effective).", arg, rand()%20 + 21);
         else
            snprintf(mesg, 511, "I smack thee, %s, for %d damage.", arg, rand()%20 + 1);
         mesg[511] = '\0';
      }
      else
      {
         snprintf(mesg, 511, "Behold, I smack thee, %s, for %d damage.", irc_nick, rand()%20 + 1);
         mesg[511] = '\0';
      }
      if ( irc_msg(irc->s, irc->channel, mesg) < 0 )
         return -1;
   }
   else if ( strcmp(command, "pacman") == 0 )
   {
      if ( irc_msg(irc->s, irc->channel, "Wocka, wocka, bitches!") < 0 )
         return -1;
   }
   else if ( strcmp(command, "google") == 0 )
   {
      char mesg[512];

      char t_nick[128];
      char t_link[256];
      char link[256] = {0};

      char *t_arg = strtok(arg, " ");
      if ( t_arg )
      {
         strncpy(t_nick, t_arg, 127);
         t_nick[127] = '\0';
      }
      else
         return 0;

      t_arg = strtok(NULL, "");
      if ( t_arg )
      {
         while ( *t_arg == ' ' )
            t_arg++;

         strncpy(t_link, t_arg, 255);
         t_link[255] = '\0';
      }
      else
         return 0;

      t_arg = strtok(t_link, " ");
      while ( t_arg )
      {
         strncpy(&link[strlen(link)], t_arg, 254 - strlen(link));

         t_arg = strtok(NULL, " ");
         if ( !t_arg )
            break;

         strncpy(&link[strlen(link)], "%20", 254 - strlen(link));
      }



      snprintf(mesg, 511, "%s: http://lmgtfy.com/?q=%s", t_nick, link);
      mesg[511] = '\0';
      if ( irc_msg(irc->s, irc->channel, mesg) < 0 )
         return -1;
   }
   
   return 0;
}