Example #1
0
static int irc_reply_message(irc_t *irc, const char* channel, char *irc_nick, char *msg) {
   // Checks if someone calls on the bot.
   if ( msg[0] != '!' ) {
      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 ( strncmp(command, "ping", strlen("ping")) == 0) {
    //return cmd_ping;
    if ( irc_msg(irc->s, channel, strncat(irc_nick, ": pong", strlen(": pong"))) < 0)
      return -1;
  } 
  else if ( strncmp(command, "bajr", strlen("bajr")) == 0 ) {
    if ( irc_msg(irc->s, channel, strncat(irc_nick, ": bajrbajrbajr", strlen(": bajrbajrbajr"))) < 0 )
      return -1;
  } 
  else {
    char reply[MSG_LEN];
    sprintf(reply, "Sorry, %s, I don't know how to do that.", irc_nick);
    if ( irc_msg(irc->s, channel, reply) < 0 )
      return -1;
  }
  return 0;
}
Example #2
0
File: on.c Project: trapped/meCh
static void
tell_on(Module *m, char **args, enum irc_type type)
{
	LastSeen *l;
	char buf[IRC_MSG_LEN], notfirst = 0;
	int minutes;
	time_t now;
	double dt, seconds;

	if(type==T_CHAN) {
		strcpy(buf, args[0]);
		strcat(buf, ": ");
	}
	else buf[0] = '\0';

	if(*args[2]) {
		minutes = proper_atoi(args[2]);
		if(minutes<0) {
			strcat(buf, usage);
			goto say;
		}

		strcat(buf, "Seen on the last ");
		strcat(buf, args[2]);
		strcat(buf, " minutes: ");
	} else {
		minutes = DEFAULT_MINUTES;
		strcat(buf, min_default);
	}

	seconds = ((double)minutes) * 60.;
	time(&now);
	l = base.next;
	while(l) {
		dt = difftime(now, l->seen);
		if(dt<seconds) {
			if(!notfirst) notfirst = 1;
			else strcat_msg(buf, ", ");
			strcat_msg(buf, l->name);
		}
		l = l->next;
	}
say:
	if(type==T_CHAN) irc_say(buf);
	else irc_msg(args[0], buf);
}
Example #3
0
static void
help(char **args, enum irc_type type)
{
	char buf[IRC_MSG_LEN], act;
	int i, j, with_S0_total_len;
	Module *m = &mod;
	/* i is the string index of the message we build. j is the string index of m->help. */

	if(type==T_CHAN) {
		sprintf(buf, "%s: I'll send you the help in a private message.", args[0]);
		irc_say(buf);
	}

	do {
		for(i=0; i<IRC_MSG_LEN-2 && (buf[i]=m->name[i]); i++);
		buf[i] = ':';
		i++;
		buf[i] = ' ';
		i++;
		for(j=0; i<IRC_MSG_LEN && (act=m->help[j]); j++, i++) {
			if(act!='$') {
				buf[i] = act;
				continue;
			}
			j++;
			if(!(act=m->help[j]) || act!='0') break;
			if(!m->invoker) {
				printf("Module %s doesn't have an invoker, cannot use $0 in help!\n", m->name);
				exit(EXIT_FAILURE);
			}
			with_S0_total_len = i + S0_base_len + 2*strlen(m->invoker);

			if(with_S0_total_len < IRC_MSG_LEN) {
				sprintf(buf+i, S0_string, m->invoker, m->invoker);
				i = with_S0_total_len-1;
			}
		}
		buf[i] = '\0';
		irc_msg(args[0], buf);
		m = m->next;
	} while(m);
}
Example #4
0
File: irc.c Project: rhaps0dy/meCh
void
irc_connect(void)
{
	struct sockaddr_in addr;
	struct hostent *serv;
	char buf[IRC_MSG_LEN];

	fd = socket(AF_INET, SOCK_STREAM/*|SOCK_NONBLOCK*/, 0);
	printf("Connecting to %s...\n", conf.host);
	serv = gethostbyname(conf.host);
	addr.sin_family = AF_INET;
	memcpy(&addr.sin_addr.s_addr, serv->h_addr_list[0], serv->h_length);
	addr.sin_port = htons(conf.port);
	if(connect(fd, (struct sockaddr *) &addr, sizeof(addr))<0) {
		puts("Connection error");
		exit(EXIT_FAILURE);
	}
	irc_read(buf);
	irc_read(buf);
	sprintf(buf, "USER %s %s %s %s", conf.name, conf.name, conf.name, conf.name);
	irc_cmd(buf);
	sprintf(buf, "NICK %s", conf.name);
	irc_cmd(buf);
	irc_read(buf);
	buf[1] = 'O';
	irc_cmd(buf);
	while(irc_read(buf)) {
		buf[strlen(conf.name)+1] = '\0';
		if(!strcmp(buf+1, conf.name)) break;
	}
	sprintf(buf, "identify %s", conf.password);
	irc_msg("NickServ", buf);
	sprintf(buf, "JOIN %s", conf.chan);
	irc_cmd(buf);
	puts("Connected!");
	sprintf(buf, "Hello, I'm %s!", conf.name);
	irc_say(buf);
}
Example #5
0
File: irc.c Project: Skeen/OSAA_IRC
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, "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;
}