Overview

Namespaces

  • Budabot
    • Core
      • Modules
    • User
      • Modules
  • None
  • Tyrence
    • Modules

Classes

  • AccessLevel
  • Budabot\Core\AccessManager
  • Budabot\Core\AdminManager
  • Budabot\Core\AOChat
  • Budabot\Core\AOChatPacket
  • Budabot\Core\AOChatQueue
  • Budabot\Core\AOExtMsg
  • Budabot\Core\AsyncHttp
  • Budabot\Core\AutoInject
  • Budabot\Core\BotRunner
  • Budabot\Core\Budabot
  • Budabot\Core\BuddylistManager
  • Budabot\Core\CacheManager
  • Budabot\Core\CacheResult
  • Budabot\Core\ClassLoader
  • Budabot\Core\ColorSettingHandler
  • Budabot\Core\CommandAlias
  • Budabot\Core\CommandManager
  • Budabot\Core\ConfigFile
  • Budabot\Core\DB
  • Budabot\Core\DBRow
  • Budabot\Core\EventLoop
  • Budabot\Core\EventManager
  • Budabot\Core\GuildChannelCommandReply
  • Budabot\Core\GuildManager
  • Budabot\Core\HelpManager
  • Budabot\Core\Http
  • Budabot\Core\HttpRequest
  • Budabot\Core\LegacyLogger
  • Budabot\Core\LimitsController
  • Budabot\Core\LoggerWrapper
  • Budabot\Core\MMDBParser
  • Budabot\Core\Modules\AdminController
  • Budabot\Core\Modules\AliasController
  • Budabot\Core\Modules\AltInfo
  • Budabot\Core\Modules\AltsController
  • Budabot\Core\Modules\BanController
  • Budabot\Core\Modules\BuddylistController
  • Budabot\Core\Modules\ColorsController
  • Budabot\Core\Modules\CommandlistController
  • Budabot\Core\Modules\CommandSearchController
  • Budabot\Core\Modules\ConfigController
  • Budabot\Core\Modules\EventlistController
  • Budabot\Core\Modules\HelpController
  • Budabot\Core\Modules\LogsController
  • Budabot\Core\Modules\PlayerLookupController
  • Budabot\Core\Modules\ProfileCommandReply
  • Budabot\Core\Modules\ProfileController
  • Budabot\Core\Modules\SettingsController
  • Budabot\Core\Modules\SQLController
  • Budabot\Core\Modules\SystemController
  • Budabot\Core\Modules\UsageController
  • Budabot\Core\Modules\WhitelistController
  • Budabot\Core\NumberSettingHandler
  • Budabot\Core\OptionsSettingHandler
  • Budabot\Core\PlayerHistory
  • Budabot\Core\PlayerHistoryManager
  • Budabot\Core\PlayerManager
  • Budabot\Core\Preferences
  • Budabot\Core\PrivateChannelCommandReply
  • Budabot\Core\PrivateMessageCommandReply
  • Budabot\Core\Registry
  • Budabot\Core\SettingHandler
  • Budabot\Core\SettingManager
  • Budabot\Core\SettingObject
  • Budabot\Core\SocketManager
  • Budabot\Core\SocketNotifier
  • Budabot\Core\SubcommandManager
  • Budabot\Core\Text
  • Budabot\Core\TextSettingHandler
  • Budabot\Core\Timer
  • Budabot\Core\TimerEvent
  • Budabot\Core\TimeSettingHandler
  • Budabot\Core\Util
  • Budabot\Core\xml
  • Budabot\User\Modules\AlienArmorController
  • Budabot\User\Modules\AlienBioController
  • Budabot\User\Modules\AlienMiscController
  • Budabot\User\Modules\AOSpeakController
  • Budabot\User\Modules\AOUController
  • Budabot\User\Modules\AXPController
  • Budabot\User\Modules\BankController
  • Budabot\User\Modules\BosslootController
  • Budabot\User\Modules\BroadcastController
  • Budabot\User\Modules\BuffPerksController
  • Budabot\User\Modules\CacheController
  • Budabot\User\Modules\ChatAssistController
  • Budabot\User\Modules\ChatCheckController
  • Budabot\User\Modules\ChatLeaderController
  • Budabot\User\Modules\ChatRallyController
  • Budabot\User\Modules\ChatSayController
  • Budabot\User\Modules\ChatTopicController
  • Budabot\User\Modules\CityWaveController
  • Budabot\User\Modules\CloakController
  • Budabot\User\Modules\ClusterController
  • Budabot\User\Modules\CountdownController
  • Budabot\User\Modules\DevController
  • Budabot\User\Modules\DingController
  • Budabot\User\Modules\EventsController
  • Budabot\User\Modules\FightController
  • Budabot\User\Modules\FindOrgController
  • Budabot\User\Modules\FindPlayerController
  • Budabot\User\Modules\FunController
  • Budabot\User\Modules\GitController
  • Budabot\User\Modules\GuideController
  • Budabot\User\Modules\GuildController
  • Budabot\User\Modules\HelpbotController
  • Budabot\User\Modules\HtmlDecodeController
  • Budabot\User\Modules\ImplantController
  • Budabot\User\Modules\ImplantDesignerController
  • Budabot\User\Modules\InactiveMemberController
  • Budabot\User\Modules\ItemsController
  • Budabot\User\Modules\KillOnSightController
  • Budabot\User\Modules\LevelController
  • Budabot\User\Modules\LinksController
  • Budabot\User\Modules\LootListsController
  • Budabot\User\Modules\MdbController
  • Budabot\User\Modules\MessageInfoCommandReply
  • Budabot\User\Modules\MockCommandReply
  • Budabot\User\Modules\NanoController
  • Budabot\User\Modules\NewsController
  • Budabot\User\Modules\NotesController
  • Budabot\User\Modules\OnlineController
  • Budabot\User\Modules\OrgHistoryController
  • Budabot\User\Modules\OrglistController
  • Budabot\User\Modules\OrgMembersController
  • Budabot\User\Modules\OSController
  • Budabot\User\Modules\PlayerHistoryController
  • Budabot\User\Modules\PlayfieldController
  • Budabot\User\Modules\PocketbossController
  • Budabot\User\Modules\PremadeImplantController
  • Budabot\User\Modules\PrivateChannelController
  • Budabot\User\Modules\QuoteController
  • Budabot\User\Modules\RaffleController
  • Budabot\User\Modules\RaidController
  • Budabot\User\Modules\RandomController
  • Budabot\User\Modules\RecipeController
  • Budabot\User\Modules\RelayController
  • Budabot\User\Modules\ReputationController
  • Budabot\User\Modules\ResearchController
  • Budabot\User\Modules\RunAsController
  • Budabot\User\Modules\SendTellController
  • Budabot\User\Modules\ShoppingController
  • Budabot\User\Modules\SilenceController
  • Budabot\User\Modules\SkillsController
  • Budabot\User\Modules\SpiritsController
  • Budabot\User\Modules\StopwatchController
  • Budabot\User\Modules\Teamspeak3
  • Budabot\User\Modules\TeamspeakController
  • Budabot\User\Modules\TestController
  • Budabot\User\Modules\TimeController
  • Budabot\User\Modules\TimerController
  • Budabot\User\Modules\TimezoneController
  • Budabot\User\Modules\TowerController
  • Budabot\User\Modules\TrackerController
  • Budabot\User\Modules\TrickleController
  • Budabot\User\Modules\UnixtimeController
  • Budabot\User\Modules\VoteController
  • Budabot\User\Modules\WeatherController
  • Budabot\User\Modules\WhatBuffsController
  • Budabot\User\Modules\WhereisController
  • Budabot\User\Modules\WhoisController
  • Budabot\User\Modules\WhoisOrgController
  • Budabot\User\Modules\WhompahController
  • Command
  • DefaultStatus
  • DefineCommand
  • Description
  • Event
  • HandlesCommand
  • Help
  • Inject
  • Instance
  • Intoptions
  • Matches
  • Options
  • Setting
  • Setup
  • Type
  • Tyrence\Modules\DemoResponseCommandReply
  • Tyrence\Modules\SameChannelResponseController
  • Visibility

Interfaces

  • Budabot\Core\CommandReply

Exceptions

  • Budabot\Core\InvalidHttpRequest
  • Budabot\Core\SQLException
  • Budabot\Core\StopExecutionException

Functions

  • Budabot\Core\isWindows
  • Budabot\Core\Modules\read_input
  • Overview
  • Namespace
  • Class
  1: <?php
  2: 
  3: namespace Budabot\Core\Modules;
  4: 
  5: use stdClass;
  6: use Budabot\Core\CommandAlias;
  7: 
  8: /**
  9:  * Authors:
 10:  *  - Tyrence (RK2)
 11:  *
 12:  * @Instance
 13:  *
 14:  * Commands this class contains:
 15:  *  @DefineCommand(
 16:  *      command       = 'usage',
 17:  *      accessLevel   = 'guild',
 18:  *      description   = 'Shows usage stats',
 19:  *      help          = 'usage.txt',
 20:  *      defaultStatus = '1'
 21:  *  )
 22:  */
 23: class UsageController {
 24:     /**
 25:      * Name of the module.
 26:      * Set automatically by module loader.
 27:      */
 28:     public $moduleName;
 29: 
 30:     /** @Inject */
 31:     public $db;
 32: 
 33:     /** @Inject */
 34:     public $http;
 35: 
 36:     /** @Inject */
 37:     public $settingManager;
 38: 
 39:     /** @Inject */
 40:     public $eventManager;
 41: 
 42:     /** @Inject */
 43:     public $util;
 44:     
 45:     /** @Inject */
 46:     public $text;
 47: 
 48:     /** @Inject */
 49:     public $chatBot;
 50: 
 51:     /**
 52:      * @Setup
 53:      */
 54:     public function setup() {
 55:         $this->db->loadSQLFile($this->moduleName, 'usage');
 56:         
 57:         $this->settingManager->add($this->moduleName, "record_usage_stats", "Record usage stats", "edit", "options", "1", "true;false", "1;0");
 58:         $this->settingManager->add($this->moduleName, 'botid', 'Botid', 'noedit', 'text', '');
 59:         $this->settingManager->add($this->moduleName, 'last_submitted_stats', 'last_submitted_stats', 'noedit', 'text', 0);
 60:     }
 61:     
 62:     /**
 63:      * @HandlesCommand("usage")
 64:      * @Matches("/^usage player ([0-9a-z-]+)$/i")
 65:      * @Matches("/^usage player ([0-9a-z-]+) ([a-z0-9]+)$/i")
 66:      */
 67:     public function usagePlayerCommand($message, $channel, $sender, $sendto, $args) {
 68:         if (count($args) == 3) {
 69:             $time = $this->util->parseTime($args[2]);
 70:             if ($time == 0) {
 71:                 $msg = "Please enter a valid time.";
 72:                 $sendto->reply($msg);
 73:                 return;
 74:             }
 75:             $time = $time;
 76:         } else {
 77:             $time = 604800;
 78:         }
 79: 
 80:         $timeString = $this->util->unixtimeToReadable($time);
 81:         $time = time() - $time;
 82:     
 83:         $player = ucfirst(strtolower($args[1]));
 84:     
 85:         $sql = "SELECT command, COUNT(command) AS count FROM usage_<myname> WHERE sender = ? AND dt > ? GROUP BY command ORDER BY count DESC";
 86:         $data = $this->db->query($sql, $player, $time);
 87:         $count = count($data);
 88: 
 89:         if ($count > 0) {
 90:             $blob .= '';
 91:             forEach ($data as $row) {
 92:                 $blob .= "<highlight>{$row->command}<end> ({$row->count})\n";
 93:             }
 94: 
 95:             $msg = $this->text->makeBlob("Usage for $player - $timeString ($count)", $blob);
 96:         } else {
 97:             $msg = "No usage statistics found for <highlight>$player<end>.";
 98:         }
 99:         $sendto->reply($msg);
100:     }
101:     
102:     /**
103:      * @HandlesCommand("usage")
104:      * @Matches("/^usage cmd ([0-9a-z_-]+)$/i")
105:      * @Matches("/^usage cmd ([0-9a-z_-]+) ([a-z0-9]+)$/i")
106:      */
107:     public function usageCmdCommand($message, $channel, $sender, $sendto, $args) {
108:         if (count($args) == 3) {
109:             $time = $this->util->parseTime($args[2]);
110:             if ($time == 0) {
111:                 $msg = "Please enter a valid time.";
112:                 $sendto->reply($msg);
113:                 return;
114:             }
115:             $time = $time;
116:         } else {
117:             $time = 604800;
118:         }
119: 
120:         $timeString = $this->util->unixtimeToReadable($time);
121:         $time = time() - $time;
122:     
123:         $cmd = strtolower($args[1]);
124:     
125:         $sql = "SELECT sender, COUNT(sender) AS count FROM usage_<myname> WHERE command = ? AND dt > ? GROUP BY sender ORDER BY count DESC";
126:         $data = $this->db->query($sql, $cmd, $time);
127:         $count = count($data);
128: 
129:         if ($count > 0) {
130:             $blob .= '';
131:             forEach ($data as $row) {
132:                 $blob .= "<highlight>{$row->sender}<end> ({$row->count})\n";
133:             }
134: 
135:             $msg = $this->text->makeBlob("Usage for $cmd - $timeString ($count)", $blob);
136:         } else {
137:             $msg = "No usage statistics found for <highlight>$cmd<end>.";
138:         }
139:         $sendto->reply($msg);
140:     }
141:     
142:     /**
143:      * @HandlesCommand("usage")
144:      * @Matches("/^usage$/i")
145:      * @Matches("/^usage ([a-z0-9]+)$/i")
146:      */
147:     public function usageCommand($message, $channel, $sender, $sendto, $args) {
148:         if (count($args) == 2) {
149:             $time = $this->util->parseTime($args[1]);
150:             if ($time == 0) {
151:                 $msg = "Please enter a valid time.";
152:                 $sendto->reply($msg);
153:                 return;
154:             }
155:             $time = $time;
156:         } else {
157:             $time = 604800;
158:         }
159: 
160:         $timeString = $this->util->unixtimeToReadable($time);
161:         $time = time() - $time;
162:         $limit = 25;
163:         
164:         // channel usage
165:         $sql = "SELECT type, COUNT(type) cnt FROM usage_<myname> WHERE dt > ? GROUP BY type ORDER BY type";
166:         $data = $this->db->query($sql, $time);
167:         
168:         $blob = "<header2>Channel Usage<end>\n";
169:         forEach ($data as $row) {
170:             if ($row->type == "msg") {
171:                 $blob .= "Number of commands executed in tells: <highlight>$row->cnt<end>\n";
172:             } else if ($row->type == "priv") {
173:                 $blob .= "Number of commands executed in private channel: <highlight>$row->cnt<end>\n";
174:             } else if ($row->type == "guild") {
175:                 $blob .= "Number of commands executed in guild channel: <highlight>$row->cnt<end>\n";
176:             }
177:         }
178:         $blob .= "\n";
179:         
180:         // most used commands
181:         $sql = "SELECT command, COUNT(command) AS count FROM usage_<myname> WHERE dt > ? GROUP BY command ORDER BY count DESC LIMIT ?";
182:         $data = $this->db->query($sql, $time, $limit);
183: 
184:         $blob .= "<header2>$limit Most Used Commands<end>\n";
185:         forEach ($data as $row) {
186:             $commandLink = $this->text->makeChatcmd($row->command, "/tell <myname> usage cmd $row->command");
187:             $blob .= "{$commandLink} ({$row->count})\n";
188:         }
189: 
190:         // users who have used the most commands
191:         $sql = "SELECT sender, COUNT(sender) AS count FROM usage_<myname> WHERE dt > ? GROUP BY sender ORDER BY count DESC LIMIT ?";
192:         $data = $this->db->query($sql, $time, $limit);
193: 
194:         $blob .= "\n<header2>$limit Most Active Users<end>\n";
195:         forEach ($data as $row) {
196:             $senderLink = $this->text->makeChatcmd($row->sender, "/tell <myname> usage player $row->sender");
197:             $blob .= "{$senderLink} ({$row->count})\n";
198:         }
199: 
200:         $msg = $this->text->makeBlob("Usage Statistics - $timeString", $blob);
201:         $sendto->reply($msg);
202:     }
203: 
204:     public function record($type, $cmd, $sender, $handler) {
205:         // don't record stats for !grc command or command aliases
206:         if ($cmd == 'grc' || "CommandAlias.process" == $handler) {
207:             return;
208:         }
209: 
210:         $sql = "INSERT INTO usage_<myname> (type, command, sender, dt) VALUES (?, ?, ?, ?)";
211:         $this->db->exec($sql, $type, $cmd, $sender, time());
212:     }
213: 
214:     /**
215:      * @Event("timer(24hrs)")
216:      * @Description("Submits anonymous usage stats to Budabot website")
217:      * @DefaultStatus("1")
218:      */
219:     public function submitAnonymousUsage($eventObj) {
220:         $debug = false;
221:         $time = time();
222:         $settingName = 'last_submitted_stats';
223:         $lastSubmittedStats = $this->settingManager->get($settingName);
224: 
225:         $postArray['stats'] = json_encode($this->getUsageInfo($lastSubmittedStats, $time, $debug));
226: 
227:         $url = 'http://stats.budabot.jkbff.com/stats/submitUsage.php';
228:         $this->http->post($url)->withQueryParams($postArray);
229: 
230:         $this->settingManager->save($settingName, $time);
231:     }
232: 
233:     public function getUsageInfo($lastSubmittedStats, $now, $debug = false) {
234:         global $version;
235: 
236:         $botid = $this->settingManager->get('botid');
237:         if ($botid == '') {
238:             $botid = $this->util->genRandomString(20);
239:             $this->settingManager->save('botid', $botid);
240:         }
241: 
242:         $sql = "SELECT type, command FROM usage_<myname> WHERE dt >= ? AND dt < ?";
243:         $data = $this->db->query($sql, $lastSubmittedStats, $now);
244: 
245:         $settings = array();
246:         $settings['dimension'] = $this->chatBot->vars['dimension'];
247:         $settings['is_guild_bot'] = ($this->chatBot->vars['my_guild'] == '' ? '0' : '1');
248:         $settings['guildsize'] = $this->getGuildSizeClass(count($this->chatBot->guildmembers));
249:         $settings['using_chat_proxy'] = $this->chatBot->vars['use_proxy'];
250:         $settings['db_type'] = $this->db->getType();
251:         $settings['bot_version'] = $version;
252:         $settings['using_git'] = (file_exists("./modules/GIT_MODULE/GitController.class.php") === true ? '1' : '0');
253:         $settings['os'] = (\budabot\core\isWindows() === true ? 'Windows' : 'Other');
254:         
255:         $settings['symbol'] = $this->settingManager->get('symbol');
256:         $settings['relay_enabled'] = ($this->settingManager->get('relaybot') == 'Off' ? '0' : '1');
257:         $settings['relay_type'] = $this->settingManager->get('relaytype');
258:         $settings['first_and_last_alt_only'] = $this->settingManager->get('first_and_last_alt_only');
259:         $settings['aodb_db_version'] = $this->settingManager->get('aodb_db_version');
260:         $settings['max_blob_size'] = $this->settingManager->get('max_blob_size');
261:         $settings['online_show_org_guild'] = $this->settingManager->get('online_show_org_guild');
262:         $settings['online_show_org_priv'] = $this->settingManager->get('online_show_org_priv');
263:         $settings['online_admin'] = $this->settingManager->get('online_admin');
264:         $settings['relay_symbol_method'] = $this->settingManager->get('relay_symbol_method');
265:         $settings['http_server_enable'] = ($this->eventManager->getKeyForCronEvent("60", "httpservercontroller.startHTTPServer") != null ? "1" : "0");
266:         $settings['tower_attack_spam'] = $this->settingManager->get('tower_attack_spam');
267: 
268:         $obj = new stdClass;
269:         $obj->id = sha1($botid . $this->chatBot->vars['name'] . $this->chatBot->vars['dimension']);
270:         $obj->version = "2";
271:         $obj->debug = ($debug == true ? '1' : '0');
272:         $obj->commands = $data;
273:         $obj->settings = $settings;
274: 
275:         return $obj;
276:     }
277: 
278:     public function getGuildSizeClass($size) {
279:         $guildClass = "";
280:         if ($size == 0) {
281:             $guildClass = "class0";
282:         } else if ($size < 10) {
283:             $guildClass = "class1";
284:         } else if ($size < 30) {
285:             $guildClass = "class2";
286:         } else if ($size < 150) {
287:             $guildClass = "class3";
288:         } else if ($size < 300) {
289:             $guildClass = "class4";
290:         } else if ($size < 650) {
291:             $guildClass = "class5";
292:         } else if ($size < 1000) {
293:             $guildClass = "class6";
294:         } else {
295:             $guildClass = "class7";
296:         }
297:         return $guildClass;
298:     }
299: }
300: 
Budabot 4 Docs API documentation generated by ApiGen