added NeonSpam Badword scanner
[NeonServV5.git] / src / modules / NeonSpam.mod / cmd_neonspam_addbad.c
diff --git a/src/modules/NeonSpam.mod/cmd_neonspam_addbad.c b/src/modules/NeonSpam.mod/cmd_neonspam_addbad.c
new file mode 100644 (file)
index 0000000..d6ca60c
--- /dev/null
@@ -0,0 +1,57 @@
+/* cmd_neonspam_addbad.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_addbad) {
+    char *cbadword = merge_argv(argv, 0, argc);
+    MYSQL_RES *res;
+    MYSQL_ROW row, defaults;
+    loadChannelSettings(chan);
+    loadNeonSpamSettings(chan);
+    struct NeonSpamSettings *settings = chan->spam_settings;
+    if(!settings) return;
+    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 reaction = atoi((row[0] ? row[0] : defaults[0])) + 1;
+    int reaction_time = atoi((row[1] ? row[1] : defaults[1]));
+    if(strlen(cbadword) > 128)
+        cbadword[128] = 0;
+    int scan_ops = ((settings->flags & SPAMSETTINGS_BADWORDSCAN_OPS) ? 1 : 0);
+    int scan_voice = ((settings->flags & SPAMSETTINGS_BADWORDSCAN_VOICE) ? 1 : 0);
+    printf_mysql_query("INSERT INTO `spamserv_badwords` (`badword_cid`, `badword_match`, `badword_use_default`, `badword_exceptlevel`, `badword_scan_ops`, `badword_scan_voice`, `badword_use_default_reaction`, `badword_reaction`, `badword_reaction_time`) VALUES ('%d', '%s', '1', '%d', '%d', '%d', '1', '%d', '%d')", chan->channel_id, escape_string(cbadword), settings->exceptlevel[SPAMSETTINGS_BADWORDEXCINDEX], scan_ops, scan_voice, reaction, reaction_time);
+    int badword_id = (int) mysql_insert_id(get_mysql_conn());
+    struct NeonSpamBadword *badword = malloc(sizeof(*badword));
+    badword->id = badword_id;
+    badword->badword = strdup(cbadword);
+    badword->use_defaults = 1;
+    badword->exceptlevel = settings->exceptlevel[SPAMSETTINGS_BADWORDEXCINDEX];
+    badword->scan_ops = scan_ops;
+    badword->scan_voice = scan_voice;
+    badword->use_default_reaction = 1;
+    badword->reaction = reaction;
+    badword->reaction_time = reaction_time;
+    badword->next = settings->badwords;
+    settings->badwords = badword;
+    reply(getTextBot(), user, "SS_BADWORD_ADDED", cbadword, badword_id);
+}