From 740649d6f206dc1f65e7550a842cf298fac7cb36 Mon Sep 17 00:00:00 2001 From: pk910 Date: Wed, 18 Jan 2012 21:20:56 +0100 Subject: [PATCH] added cmd_stats to NeonHelp --- Makefile.am | 1 + src/bot_NeonHelp.c | 4 ++ src/cmd_neonhelp.h | 1 + src/cmd_neonhelp_stats.c | 87 ++++++++++++++++++++++++++++++++++++++++ src/commands.c | 1 + 5 files changed, 94 insertions(+) create mode 100644 src/cmd_neonhelp_stats.c diff --git a/Makefile.am b/Makefile.am index 3789db9..47222e6 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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_neonhelp_stats.c \ src/cmd_funcmds.c \ src/ConfigParser.c \ src/QServer.c diff --git a/src/bot_NeonHelp.c b/src/bot_NeonHelp.c index 5e0e605..1922262 100644 --- a/src/bot_NeonHelp.c +++ b/src/bot_NeonHelp.c @@ -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_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} }; diff --git a/src/cmd_neonhelp.h b/src/cmd_neonhelp.h index d52c96c..0fce87a 100644 --- a/src/cmd_neonhelp.h +++ b/src/cmd_neonhelp.h @@ -32,5 +32,6 @@ 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 diff --git a/src/cmd_neonhelp_stats.c b/src/cmd_neonhelp_stats.c new file mode 100644 index 0000000..967e05e --- /dev/null +++ b/src/cmd_neonhelp_stats.c @@ -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 . + */ + +#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"); + } +} diff --git a/src/commands.c b/src/commands.c index 6412800..e4b6ea5 100644 --- a/src/commands.c +++ b/src/commands.c @@ -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("stats", neonhelp_cmd_stats, 0, NULL, CMDFLAG_REQUIRE_AUTH | CMDFLAG_CHECK_AUTH); #undef USER_COMMAND } \ No newline at end of file -- 2.20.1