added NeonSpam Badword scanner
[NeonServV5.git] / src / modules / NeonSpam.mod / cmd_neonspam_badwords.c
diff --git a/src/modules/NeonSpam.mod/cmd_neonspam_badwords.c b/src/modules/NeonSpam.mod/cmd_neonspam_badwords.c
new file mode 100644 (file)
index 0000000..9767e35
--- /dev/null
@@ -0,0 +1,106 @@
+/* cmd_neonspam_badwords.c - NeonServ v5.4
+ * Copyright (C) 2011-2012  Philipp Kreil (pk910)
+ * 
+ * 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 3 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, see <http://www.gnu.org/licenses/>. 
+ */
+
+#include "cmd_neonspam.h"
+
+CMD_BIND(neonspam_cmd_badwords) {
+    MYSQL_RES *res;
+    MYSQL_ROW row, defaults;
+    loadChannelSettings(chan);
+    loadNeonSpamSettings(chan);
+    struct NeonSpamSettings *settings = chan->spam_settings;
+    if(!settings) return;
+    if(argc > 0) {
+        int badword_id = atoi(argv[0]);
+        printf_mysql_query("SELECT `badword_match` FROM `spamserv_badwords` WHERE `badword_id` = '%d' AND `badword_cid` = '%d'", badword_id, chan->channel_id);
+        res = mysql_use();
+        if(!(row = mysql_fetch_row(res))) {
+            reply(getTextBot(), user, "SS_BADWORD_ID_UNKNOWN", badword_id, chan->name);
+            return;
+        }
+        //to be continued...
+        
+    } else {
+        struct Table *table;
+        printf_mysql_query("SELECT `channel_badword_reaction`, `channel_badword_reaction_duration` FROM `channels` WHERE `channel_id` = '%d'", chan->channel_id);
+        res = mysql_use();
+        row = mysql_fetch_row(res);
+        if(!row[0] || !row[1]) {
+            printf_mysql_query("SELECT `channel_badword_reaction`, `channel_badword_reaction_duration` FROM `channels` WHERE `channel_name` = 'defaults'");
+            res = mysql_use();
+            defaults = mysql_fetch_row(res);
+        }
+        int default_reaction = atoi((row[0] ? row[0] : defaults[0]));
+        int default_reaction_time = atoi((row[1] ? row[1] : defaults[1]));
+        printf_mysql_query("SELECT `badword_id`, `badword_match`, `badword_use_default`, `badword_exceptlevel`, `badword_scan_ops`, `badword_scan_voice`, `badword_use_default_reaction`, `badword_reaction`, `badword_reaction_time` FROM `spamserv_badwords` WHERE `badword_cid` = '%d' ORDER BY `badword_id` ASC", chan->channel_id);
+        res = mysql_use();
+        table = table_init(4, mysql_num_rows(res) + 1, 0);
+        char *content[4];
+        content[0] = get_language_string(user, "SS_BADWORDS_ID");
+        content[1] = get_language_string(user, "SS_BADWORDS_PATTERN");
+        content[2] = get_language_string(user, "SS_BADWORDS_SCAN");
+        content[3] = get_language_string(user, "SS_BADWORDS_REACTION");
+        table_add(table, content);
+        char default_exception[100];
+        char exception_buf[100], reaction_buf[100], reaction_time_buf[100];
+        int exception_pos = 0, reaction_pos;
+        int reaction, reaction_time;
+        if(settings->flags & SPAMSETTINGS_BADWORDSCAN_OPS)
+            exception_pos += sprintf(default_exception+exception_pos, (exception_pos ? " & @" : "@"));
+        if(settings->flags & SPAMSETTINGS_BADWORDSCAN_VOICE)
+            exception_pos += sprintf(default_exception+exception_pos, (exception_pos ? " & +" : "+"));
+        if(settings->exceptlevel[SPAMSETTINGS_BADWORDEXCINDEX])
+            exception_pos += sprintf(default_exception+exception_pos, (exception_pos ? " & <%d" : "<%d"), settings->exceptlevel[SPAMSETTINGS_BADWORDEXCINDEX]);
+        while ((row = mysql_fetch_row(res)) != NULL) {
+            content[0] = row[0];
+            content[1] = row[1];
+            exception_pos = 0;
+            if(strcmp(row[2], "0")) {
+                exception_pos += sprintf(exception_buf, "\00314%s\003", default_exception);
+            } else {
+                if(!strcmp(row[4], "1"))
+                    exception_pos += sprintf(exception_buf+exception_pos, (exception_pos ? " & @" : "@"));
+                if(!strcmp(row[5], "1"))
+                    exception_pos += sprintf(exception_buf+exception_pos, (exception_pos ? " & +" : "+"));
+                if(atoi(row[3]))
+                    exception_pos += sprintf(exception_buf+exception_pos, (exception_pos ? " & <%d" : "<%d"), atoi(row[3]));
+            }
+            content[2] = exception_buf;
+            reaction_pos = 0;
+            if(strcmp(row[6], "0")) {
+                reaction = default_reaction;
+                reaction_time = default_reaction_time;
+            } else {
+                reaction = atoi(row[7]);
+                reaction_time = atoi(row[8]);
+            }
+            sprintf(reaction_buf, "SS_BADWORDS_REACTION_%d", reaction);
+            reaction_pos += sprintf(reaction_buf, "%s", get_language_string(user, reaction_buf));
+            if(reaction == 2) {
+                reaction_pos += sprintf(reaction_buf+reaction_pos, " (%s)", timeToStr(user, reaction_time, 2, reaction_time_buf));
+            }
+            content[3] = reaction_buf;
+            table_add(table, content);
+        }
+        char **table_lines = table_end(table);
+        int i;
+        for(i = 0; i < table->entrys; i++) {
+            reply(getTextBot(), user, table_lines[i]);
+        }
+        table_free(table);
+    }
+}