forked from florian-sander/gseen.mod
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathai.c
145 lines (132 loc) · 3.31 KB
/
ai.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/*
* Copyright (C) 2000,2001 Florian Sander
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
static int quietaiseens(char *chan)
{
char buf[121], *b;
strlcpy(buf, quiet_ai_seen, sizeof buf);
b = buf;
while (b[0])
if (!strcasecmp(chan, newsplit(&b)))
return 1;
#if EGG_IS_MIN_VER(10503)
if (ngetudef("quietaiseens", chan))
return 1;
#endif
return 0;
}
static int tcl_pubmseen STDVAR
{
char *nick, *uhost, *chan, *text;
char buf[1024];
char *words, *word;
seendat *l;
int i;
BADARGS(6, 6, " nick uhost hand chan text");
nick = argv[1];
uhost = argv[2];
chan = argv[4];
text = argv[5];
reset_global_vars();
glob_slang = slang_find(coreslangs, slang_chanlang_get(chanlangs, chan));
glob_nick = nick;
for (i = 0; i < strlen(text); i++)
if (strchr("!?.,\"", text[i]))
text[i] = ' ';
strlcpy(buf, ignore_words, sizeof buf);
words = buf;
while (words[0])
add_ignoredword(newsplit(&words));
strlcpy(buf, text, sizeof buf);
words = buf;
while (words[0]) {
word = newsplit(&words);
if (word_is_ignored(word))
continue;
l = findseen(word);
if (l) {
if (quietaiseens(chan)) {
set_prefix(SLNOTPREFIX);
dprintf(DP_HELP, "NOTICE %s :%s%s\n", nick, reply_prefix,
do_seen(word, nick, uhost, chan, 0));
} else {
set_prefix(SLPUBPREFIX);
dprintf(DP_HELP, "PRIVMSG %s :%s%s\n", chan, reply_prefix,
do_seen(word, nick, uhost, chan, 0));
}
add_seenreq(word, nick, uhost, chan, now);
free_ignoredwords();
Tcl_SetResult(irp, "1", TCL_STATIC);
return TCL_OK;
}
}
free_ignoredwords();
Tcl_SetResult(irp, "0", TCL_STATIC);
return TCL_OK;
}
static tcl_cmds mytcls[] =
{
{"*pubm:seen", tcl_pubmseen},
{"*chjn:gseen", gseen_chjn},
{"*chpt:gseen", gseen_chpt},
{0, 0}
};
static void add_ignoredword(char *word)
{
ignoredword *l, *nl;
l = ignoredwords;
while (l && l->next)
l = l->next;
nl = nmalloc(sizeof(ignoredword));
nl->word = nmalloc(strlen(word) + 1);
strcpy(nl->word, word);
nl->next = NULL;
if (ignoredwords)
l->next = nl;
else
ignoredwords = nl;
}
static void free_ignoredwords()
{
ignoredword *l, *ll;
l = ignoredwords;
while (l) {
ll = l->next;
nfree(l->word);
nfree(l);
l = ll;
}
ignoredwords = NULL;
}
static int expmem_ignoredwords()
{
ignoredword *l;
int size = 0;
for (l = ignoredwords; l; l = l->next) {
size += sizeof(ignoredword);
size += strlen(l->word) + 1;
}
return size;
}
static int word_is_ignored(char *word)
{
ignoredword *l;
for (l = ignoredwords; l; l = l->next)
if (!strcasecmp(l->word, word))
return 1;
return 0;
}