strip soundcloud links slightly
[fillybot.git] / mod.h
blobb09ef289caa4d02814e106af355418af29a38fee
1 #include "shared.h"
2 #include <ctype.h>
3 #include <tdb.h>
5 static inline char *token(char **foo, char sep)
7 char *line = *foo, *ret;
8 if (!line)
9 return NULL;
10 ret = line;
11 while (*line && *line != sep)
12 line++;
13 if (*line) {
14 *(line++) = 0;
15 while (*line == sep)
16 line++;
17 *foo = *line ? line : NULL;
18 } else
19 *foo = NULL;
20 return ret;
23 static inline unsigned getrand(void)
25 unsigned rand = 0;
26 int fd = open("/dev/urandom", O_RDONLY);
27 if (fd >= 0) {
28 read(fd, &rand, sizeof(rand));
29 close(fd);
30 return rand;
32 return random();
35 struct command_hash
37 char *string;
38 void (*cmd)(struct bio *b, const char *nick, const char *host, const char *target, char *args);
39 int enter, left;
40 char failed_command[];
41 } __attribute__((aligned(256)));
43 static unsigned strhash(const char *h)
45 TDB_DATA in = { .dptr = (char*)h, .dsize = strlen(h) };
46 return tdb_jenkins_hash(&in);
49 static void __attribute__ ((__format__(__printf__, 3, 4))) privmsg(struct bio *b, const char *who, const char *fmt, ...)
51 char *buffer;
52 va_list va;
54 va_start(va, fmt);
55 vasprintf(&buffer, fmt, va);
56 va_end(va);
58 if (sopa)
59 b->writeline(b, "PRIVMSG %s :\00301,01%s", who, buffer);
60 else
61 b->writeline(b, "PRIVMSG %s :%s", who, buffer);
62 free(buffer);
65 static void __attribute__ ((__format__(__printf__, 3, 4))) action(struct bio *b, const char *who, const char *fmt, ...)
67 char *buffer;
68 va_list va;
70 va_start(va, fmt);
71 vasprintf(&buffer, fmt, va);
72 va_end(va);
74 if (sopa)
75 b->writeline(b, "PRIVMSG %s :\001ACTION \00301,01%s\001", who, buffer);
76 else
77 b->writeline(b, "PRIVMSG %s :\001ACTION %s\001", who, buffer);
78 free(buffer);