added cmd_stats to NeonHelp
authorpk910 <philipp@zoelle1.de>
Wed, 18 Jan 2012 20:20:56 +0000 (21:20 +0100)
committerpk910 <philipp@zoelle1.de>
Wed, 18 Jan 2012 20:24:35 +0000 (21:24 +0100)
Makefile.am
src/bot_NeonHelp.c
src/cmd_neonhelp.h
src/cmd_neonhelp_stats.c [new file with mode: 0644]
src/commands.c

index 3789db908cad16585f98843bc09a8d67d30ceb61..47222e6cf91326166f898f35317f9f8e561fe2de 100644 (file)
@@ -133,6 +133,7 @@ neonserv_SOURCES = src/version.c \
       src/cmd_neonserv_dehalfop.c \
       src/cmd_neonserv_halfopall.c \
       src/cmd_neonserv_dehalfopall.c \
       src/cmd_neonserv_dehalfop.c \
       src/cmd_neonserv_halfopall.c \
       src/cmd_neonserv_dehalfopall.c \
+      src/cmd_neonhelp_stats.c \
       src/cmd_funcmds.c \
       src/ConfigParser.c \
       src/QServer.c
       src/cmd_funcmds.c \
       src/ConfigParser.c \
       src/QServer.c
index 5e0e605076c9e3409f240ea6ef65536c7e9de80b..1922262a33ca4606e7ddedbeb92af86bb1ce7674 100644 (file)
@@ -60,6 +60,10 @@ static const struct default_language_entry msgtab[] = {
     {"NH_REQUESTS_STATE_ACTIVE", "active"},
     {"NH_REQUESTS_STATE_PENDING", "pending"},
     {"NH_REQUESTS_STATE_ERROR", "ERROR"},
     {"NH_REQUESTS_STATE_ACTIVE", "active"},
     {"NH_REQUESTS_STATE_PENDING", "pending"},
     {"NH_REQUESTS_STATE_ERROR", "ERROR"},
+    {"NH_STATS_HEADER_USER", "User"},
+    {"NH_STATS_HEADER_LAST_24H", "last 24h"},
+    {"NH_STATS_HEADER_LAST_7DAY", "last 7d"},
+    {"NH_STATS_HEADER_LAST_30DAY", "last 30d"},
     {NULL, NULL}
 };
 
     {NULL, NULL}
 };
 
index d52c96c73ece03783e5a94226e28717947cc4df4..0fce87a940d50f0e0f33da22d94e4e13b3b6dd65 100644 (file)
@@ -32,5 +32,6 @@
 CMD_BIND(neonhelp_cmd_delete);
 CMD_BIND(neonhelp_cmd_next);
 CMD_BIND(neonhelp_cmd_requests);
 CMD_BIND(neonhelp_cmd_delete);
 CMD_BIND(neonhelp_cmd_next);
 CMD_BIND(neonhelp_cmd_requests);
+CMD_BIND(neonhelp_cmd_stats);
 
 #endif
\ No newline at end of file
 
 #endif
\ No newline at end of file
diff --git a/src/cmd_neonhelp_stats.c b/src/cmd_neonhelp_stats.c
new file mode 100644 (file)
index 0000000..967e05e
--- /dev/null
@@ -0,0 +1,87 @@
+/* cmd_neonhelp_stats.c - NeonServ v5.3
+ * 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_neonhelp.h"
+
+/*
+* argv[0]   user
+*/
+
+CMD_BIND(neonhelp_cmd_stats) {
+    //check permissions
+    MYSQL_RES *res;
+    MYSQL_ROW row, row2;
+    int caccess = 0;
+    printf_mysql_query("SELECT `helpserv_support`, `helpserv_public`, `helpserv_intern` FROM `helpserv_settings` WHERE `helpserv_botid` = '%d'", client->clientid);
+    res = mysql_use();
+    if (!(row = mysql_fetch_row(res))) return;
+    //check if the user is a supporter (access in the support channel)
+    if((user->flags & USERFLAG_ISAUTHED)) {
+        int userid;
+        if(user->flags & USERFLAG_HAS_USERID)
+            userid = user->user_id;
+        else {
+            printf_mysql_query("SELECT `user_id` FROM `users` WHERE `user_user` = '%s'", escape_string(user->auth));
+            res = mysql_use();
+            if ((row2 = mysql_fetch_row(res)) != NULL) {
+                userid = atoi(row2[0]);
+                user->user_id = userid;
+                user->flags |= USERFLAG_HAS_USERID;
+            } else
+                userid = 0;
+        }
+        printf_mysql_query("SELECT `chanuser_access`, `chanuser_flags` FROM `chanusers` LEFT JOIN `channels` ON `chanuser_cid` = `channel_id` WHERE `chanuser_uid` = '%d' AND `channel_name` = '%s'", userid, escape_string(row[0]));
+        res = mysql_use();
+        if ((row2 = mysql_fetch_row(res)) != NULL) {
+            int cflags = atoi(row2[1]);
+            if(!(cflags & DB_CHANUSER_SUSPENDED))
+                caccess = atoi(row2[0]);
+        }
+    }
+    if(!caccess) {
+        reply(getTextBot(), user, "MODCMD_ACCESS_DENIED");
+        return;
+    }
+    if(argc > 0) {
+        //following
+    } else {
+        struct Table *table;
+        printf_mysql_query("SELECT DISTINCT a.`supporter`, `user_user`, (SELECT COUNT(*) FROM `helpserv_requests` AS b WHERE b.`supporter` = a.`supporter` AND b.`time` > (UNIX_TIMESTAMP()-(3600*24))), (SELECT COUNT(*) FROM `helpserv_requests` AS b WHERE b.`supporter` = a.`supporter` AND b.`time` > (UNIX_TIMESTAMP()-(3600*24*7))), (SELECT COUNT(*) FROM `helpserv_requests` AS b WHERE b.`supporter` = a.`supporter` AND b.`time` > (UNIX_TIMESTAMP()-(3600*24*7*4))) FROM `helpserv_requests` AS a LEFT JOIN `users` ON a.`supporter` = `user_id` WHERE a.`time` > (UNIX_TIMESTAMP()-(3600*24*7*4))  AND `botid` = '%d' ORDER BY `user_user` ASC", client->clientid);
+        res = mysql_use();
+        table = table_init(4, mysql_num_rows(res) + 1, 0);
+        char *content[4];
+        content[0] = get_language_string(user, "NH_STATS_HEADER_USER");
+        content[1] = get_language_string(user, "NH_STATS_HEADER_LAST_24H");
+        content[2] = get_language_string(user, "NH_STATS_HEADER_LAST_7DAY");
+        content[3] = get_language_string(user, "NH_STATS_HEADER_LAST_30DAY");
+        table_add(table, content);
+        while ((row = mysql_fetch_row(res)) != NULL) {
+            content[0] = (strcmp(row[0], "-1") ? row[1] : "-");
+            content[1] = row[2];
+            content[2] = row[3];
+            content[3] = row[4];
+            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]);
+        }
+        if(table->entrys == 1)
+            reply(getTextBot(), user, "NS_TABLE_NONE");
+    }
+}
index 64128000d151a0fd59cc2ab890afdbcceef6f15e..e4b6ea59c2e2e25a703c0366909150cd9d2e310d 100644 (file)
@@ -170,6 +170,7 @@ void register_commands() {
     USER_COMMAND("next",         neonhelp_cmd_next,      0, NULL,                   CMDFLAG_REQUIRE_AUTH | CMDFLAG_CHECK_AUTH);
     USER_COMMAND("delete",       neonhelp_cmd_delete,    1, NULL,                   CMDFLAG_REQUIRE_AUTH | CMDFLAG_CHECK_AUTH);
     USER_COMMAND("requests",     neonhelp_cmd_requests,  0, NULL,                   CMDFLAG_REQUIRE_AUTH | CMDFLAG_CHECK_AUTH);
     USER_COMMAND("next",         neonhelp_cmd_next,      0, NULL,                   CMDFLAG_REQUIRE_AUTH | CMDFLAG_CHECK_AUTH);
     USER_COMMAND("delete",       neonhelp_cmd_delete,    1, NULL,                   CMDFLAG_REQUIRE_AUTH | CMDFLAG_CHECK_AUTH);
     USER_COMMAND("requests",     neonhelp_cmd_requests,  0, NULL,                   CMDFLAG_REQUIRE_AUTH | CMDFLAG_CHECK_AUTH);
+    USER_COMMAND("stats",        neonhelp_cmd_stats,     0, NULL,                   CMDFLAG_REQUIRE_AUTH | CMDFLAG_CHECK_AUTH);
     #undef USER_COMMAND
     
 }
\ No newline at end of file
     #undef USER_COMMAND
     
 }
\ No newline at end of file