Beispiel #1
0
static
char *test_irc_notice() {
    bstring expected;

    expected = bfromcstr("NOTICE someBloke :Message for someBloke!\r\n");
    irc_notice(SOCK, "someBloke", "Message for someBloke!");
    mu_assert("Empty message", blength(sent) != 0);
    mu_assert("Message differs from expected", bstrcmp(expected, sent) == 0);
    bdestroy(expected);
    bdestroy(sent);

    return NULL;
}
Beispiel #2
0
void command_fail(int reason, irc_user_t *origin, const char *command)
{
    command_t *cmd;

    cmd = command_find(command);

    switch(reason)
    {
        case CMD_BADPARAM:
            irc_notice(origin->nick, "Incorrect parameters for \2%s\2", cmd->name);
            irc_notice(origin->nick, "Syntax: %s", cmd->syntax);
            break;

        case CMD_NEEDSPARAM:
            irc_notice(origin->nick, "Insufficient parameters for \2%s\2", cmd->name);
            irc_notice(origin->nick, "Syntax: %s", cmd->syntax);
            break;
        
        case CMD_NOAUTH:
            irc_notice(origin->nick, "You are not authorised to use \2%s\2", cmd->name);
            break;
    }
}
Beispiel #3
0
int reply(info_t * in) {
  int remain;
  char buf[512];

  if (in->cmd == cmd_privmsg) {
    in->tail = skip_nick(in->tail, in->me);
    if(!tail_cmd(&in->tail, "fortune")
        && randomline(buf, sizeof(buf)) != NULL) {
      if(time(NULL) - lasttime >= req_delay) {
        irc_privmsg(to_sender(in), "%s", buf); 
        lasttime = time(NULL);
      } else {
        remain = req_delay - (time(NULL) - lasttime);
        if(remain > 3600)
          irc_notice(in->sender_nick, "Please wait %d hours.", remain / 3600);
        else if(remain > 60)
          irc_notice(in->sender_nick, "Please wait %d minutes.", remain / 60);
        else
          irc_notice(in->sender_nick, "Please wait %d seconds.", remain);
      }
    }
  }
  return 0;
}
Beispiel #4
0
void periodic_whatcd(list_t *tracking) {
	whatcd_t *whatcd;
	list_node_t *node2;
	whatcd_request_t *request;
	whatcd_release_t *release;
	char buffer[2048], *output;
	list_t *users;
	int *trackval; /* store value for check how many errors/users waz */
	
	if(!(users = settings_by_key("whatsession", PRIVATE)))
		return;
	
	list_foreach(users, node) {
		whatcd = whatcd_new((char *) node->data);
		
		/* load error count */
		if(!(trackval = (int *) list_search(tracking, node->name))) {
			trackval = (int *) calloc(1, sizeof(int));
			list_append(tracking, node->name, trackval);
		}
		
		if(!(output = settings_get(node->name, "whatchan", PUBLIC)))
			output = node->name;
		
		/* notification failed */
		if(!(request = whatcd_notification(whatcd))) {
			printf("[-] periodic/whatcd: trackval error count for %s: %d\n", node->name, ++*trackval);
			
			if(*trackval == 4)
				irc_notice(node->name, "cannot grab your notifications, please check your whatcd session");
			
			if(*trackval == 50)
				irc_notice(node->name, "whatcd session seems really down, please check your whatcd session or unset it with: .unset whatsession");
				
			goto next_node;
		}
		
		if(request->error) {
			printf("[-] periodic/whatcd: error: %s\n", request->error);
			goto next_node;
		}
		
		node2 = request->response->nodes;
		
		while(node2) {
			release = (whatcd_release_t *) node2->data;
			node2 = node2->next;
			
			if(!release->unread)
				continue;
				
			zsnprintf(buffer,
				  "%s: [%s/%s] %s - %s (%.2f Mo): " WHATCD_TORRENT "%.0f&torrentid=%.0f",
				  node->name,
				  release->format, release->media, release->artist, release->groupname, 
				  release->size / 1024 / 1024, release->groupid,
				  release->torrentid
			);
			
			irc_privmsg(output, buffer);
			*trackval = 0;
		}
		
		next_node:
			whatcd_request_free(request);		
			whatcd_free(whatcd);
	}