Exemple #1
0
static void
do_1337(char **args, enum irc_type type)
{
	char *str, *c, buf[IRC_MSG_LEN];
	int i, j, k, n, prob, nwords;
	char *num_start[2], *num_end;

	/* check if -<prob> is passed as first argument */
	if(args[2][0] == '-') {
		nwords = words(args[2], num_start, &num_end, 2); 
		if(nwords==1)
			goto usage;
		*num_end = '\0';
		prob = proper_atoi(num_start[0]+1);
		*num_end = ' ';
		if(prob < 0)
			goto usage;
		str = num_start[1];
	} else {
		prob = DEFAULT_PROB_CONVERTING;
		str = args[2];
	}

	k = 0;
	for(; *str; str++) {
		i = conv_ind(*str);
		if(i==-1 || rand_dont_convert_this_char(prob)) {
			buf[k] = *str;
			if(k==IRC_MSG_LEN-1)
				goto end;
			k++;
			continue;
		}
		n = rand() % conv_tab[i].n;
		c = conv_tab[i].beg;
		for(j=0; j<n; j++) {
			while(*c) c++;
			c++;
		}
		while(*c) {
			buf[k] = *c;
			if(k==IRC_MSG_LEN-1)
				goto end;
			c++;
			k++;
		}
	}
end:
	buf[k] = '\0';
	irc_reply(args[0], buf, type);
	return;
usage:
	irc_reply(args[0], "Usage: .1337 -<probability> <message>", type);
}
Exemple #2
0
static int cmd_day(int argc, char **argv)
{
    int year, mon, day;
    if ((argc != 4) || (proper_atoi(argv[1], &year) != 1)
                    || (proper_atoi(argv[2], &mon) != 1)
                    || (proper_atoi(argv[3], &day) != 1)) {
        printf("Usage: %s <Year> <Month[1..12]> <Day[1..31]>\n", argv[0]);

        return 1;
    }
    else {
        if (!tm_is_valid_date(year, mon - 1, day)) {
            puts("The supplied date is invalid, but no error should occur.");
        }

        int wday, yday;
        tm_get_wyday(year, mon - 1, day, &wday, &yday);
        printf("What weekday was %04d-%02d-%02d? The %d(th) day of the year was a %.3s.\n",
               year, mon, day, yday + 1, DAY_NAMES[wday]);

        return 0;
    }
}
Exemple #3
0
static int cmd_doomsday(int argc, char **argv)
{
    int year;
    if ((argc != 2) || (proper_atoi(argv[1], &year) != 1)) {
        printf("Usage: %s <Year>\n", argv[0]);

        return 1;
    }
    else {
        printf("What weekday was MAR 0 of %d? %.3s.\n",
               year, DAY_NAMES[tm_doomsday(year) % 7]);

        return 0;
    }
}
Exemple #4
0
static int cmd_leap_year(int argc, char **argv)
{
    int year;
    if ((argc != 2) || (proper_atoi(argv[1], &year) != 1)) {
        printf("Usage: %s <Year>\n", argv[0]);

        return 1;
    }
    else {
        printf("Was %d a leap year? %.3s.\n",
               year, BOOL_NAMES[tm_is_leap_year(year)]);

        return 0;
    }
}
Exemple #5
0
static int cmd_days_in(int argc, char **argv)
{
    int mon;
    if ((argc != 2) || (proper_atoi(argv[1], &mon) != 1) || (mon < 1) || (mon > 12)) {
        printf("Usage: %s <Month[1..12]>\n", argv[0]);

        return 1;
    }
    else {
        printf("There are %d days in %.3s in common years.\n",
               TM_MON_DAYS[mon - 1], MON_NAMES[mon - 1]);

        return 0;
    }
}
Exemple #6
0
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);
}