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\User\Modules;
  4: 
  5: use Budabot\Core\AutoInject;
  6: use Budabot\Core\CommandReply;
  7: use Budabot\Core\Registry;
  8: use stdClass;
  9: 
 10: /**
 11:  * Authors: 
 12:  *  - Tyrence (RK2)
 13:  *
 14:  * @Instance
 15:  *
 16:  * Commands this controller contains:
 17:  *  @DefineCommand(
 18:  *      command     = 'test',
 19:  *      accessLevel = 'admin',
 20:  *      description = "Test the bot commands",
 21:  *      help        = 'test.txt'
 22:  *  )
 23:  *  @DefineCommand(
 24:  *      command     = 'testorgjoin',
 25:  *      accessLevel = 'admin',
 26:  *      description = "Test the bot commands",
 27:  *      help        = 'test.txt'
 28:  *  )
 29:  *  @DefineCommand(
 30:  *      command     = 'testtowerattack',
 31:  *      accessLevel = 'admin',
 32:  *      description = "Test the bot commands",
 33:  *      help        = 'test.txt'
 34:  *  )
 35:  *  @DefineCommand(
 36:  *      command     = 'testtowervictory',
 37:  *      accessLevel = 'admin',
 38:  *      description = "Test the bot commands",
 39:  *      help        = 'test.txt'
 40:  *  )
 41:  *  @DefineCommand(
 42:  *      command     = 'testos',
 43:  *      accessLevel = 'admin',
 44:  *      description = "Test the bot commands",
 45:  *      help        = 'test.txt'
 46:  *  )
 47:  *  @DefineCommand(
 48:  *      command     = 'testevent',
 49:  *      accessLevel = 'admin',
 50:  *      description = "Test the bot commands",
 51:  *      help        = 'testevent.txt'
 52:  *  )
 53:  *  @DefineCommand(
 54:  *      command     = 'testcloaklower',
 55:  *      accessLevel = 'admin',
 56:  *      description = "Test the bot commands",
 57:  *      help        = 'test.txt'
 58:  *  )
 59:  *  @DefineCommand(
 60:  *      command     = 'testcloakraise',
 61:  *      accessLevel = 'admin',
 62:  *      description = "Test the bot commands",
 63:  *      help        = 'test.txt'
 64:  *  )
 65:  *  @DefineCommand(
 66:  *      command     = 'msginfo',
 67:  *      accessLevel = 'all',
 68:  *      description = "Show number of characters in response and the time it took to process",
 69:  *      help        = 'msginfo.txt'
 70:  *  )
 71:  */
 72: class TestController extends AutoInject {
 73: 
 74:     /**
 75:      * Name of the module.
 76:      * Set automatically by module loader.
 77:      */
 78:     public $moduleName;
 79: 
 80:     /**
 81:      * @Setup
 82:      */
 83:     public function setup() {
 84:         $this->path = getcwd() . "/modules/" . $this->moduleName . "/tests/";
 85:         
 86:         $this->settingManager->add($this->moduleName, "show_test_commands", "Show test commands as they are executed", "edit", "options", "0", "true;false", "1;0");
 87:         $this->settingManager->add($this->moduleName, "show_test_results", "Show test results from test commands", "edit", "options", "0", "true;false", "1;0");
 88:     }
 89:     
 90:     /**
 91:      * @HandlesCommand("test")
 92:      * @Matches("/^test$/i")
 93:      */
 94:     public function testListCommand($message, $channel, $sender, $sendto, $args) {
 95:         $files = $this->util->getFilesInDirectory($this->path);
 96:         $count = count($files);
 97:         sort($files);
 98:         $blob = $this->text->makeChatcmd("All Tests", "/tell <myname> test all") . "\n";
 99:         forEach ($files as $file) {
100:             $name = str_replace(".txt", "", $file);
101:             $blob .= $this->text->makeChatcmd($name, "/tell <myname> test $name") . "\n";
102:         }
103:         $msg = $this->text->makeBlob("Tests Available ($count)", $blob);
104:         $sendto->reply($msg);
105:     }
106: 
107:     /**
108:      * @HandlesCommand("test")
109:      * @Matches("/^test all$/i")
110:      */
111:     public function testAllCommand($message, $channel, $sender, $sendto, $args) {
112:         $type = "msg";
113:         if ($this->setting->show_test_results == 1) {
114:             $mockSendto = $sendto;
115:         } else {
116:             $mockSendto = new MockCommandReply();
117:         }
118: 
119:         $files = $this->util->getFilesInDirectory($this->path);
120:         $starttime = time();
121:         $sendto->reply("Starting tests...");
122:         forEach ($files as $file) {
123:             $lines = file($this->path . $file, FILE_IGNORE_NEW_LINES);
124:             $this->runTests($lines, $sender, $type, $mockSendto);
125:         }
126:         $time = $this->util->unixtimeToReadable(time() - $starttime);
127:         $sendto->reply("Finished tests. Time: $time");
128:     }
129:     
130:     /**
131:      * @HandlesCommand("test")
132:      * @Matches("/^test ([a-z0-9_-]+)$/i")
133:      */
134:     public function testModuleCommand($message, $channel, $sender, $sendto, $args) {
135:         $file = $args[1] . ".txt";
136: 
137:         $type = "msg";
138:         if ($this->setting->show_test_results == 1) {
139:             $mockSendto = $sendto;
140:         } else {
141:             $mockSendto = new MockCommandReply();
142:         }
143:     
144:         $lines = file($this->path . $file, FILE_IGNORE_NEW_LINES);
145:         if ($lines === false) {
146:             $sendto->reply("Could not find test <highlight>$file<end> to run.");
147:         } else {
148:             $starttime = time();
149:             $sendto->reply("Starting test $file...");
150:             $this->runTests($lines, $sender, $type, $mockSendto);
151:             $time = $this->util->unixtimeToReadable(time() - $starttime);
152:             $sendto->reply("Finished test $file. Time: $time");
153:         }
154:     }
155:     
156:     public function runTests($commands, $sender, $type, $sendto) {
157:         forEach ($commands as $line) {
158:             if ($line[0] == "!") {
159:                 if ($this->setting->show_test_commands == 1) {
160:                     $this->chatBot->sendTell($line, $sender);
161:                 }
162:                 $line = substr($line, 1);
163:                 $this->commandManager->process($type, $line, $sender, $sendto);
164:             }
165:         }
166:     }
167:     
168:     /**
169:      * @HandlesCommand("testorgjoin")
170:      * @Matches("/^testorgjoin (.+)$/i")
171:      */
172:     public function testorgjoinCommand($message, $channel, $sender, $sendto, $args) {
173:         $packet = new stdClass;
174:         $packet->type = AOCP_GROUP_MESSAGE;
175:         $packet->args = array();
176:         $packet->args[0] = $this->chatBot->get_gid('org msg');
177:         $packet->args[1] = (int)0xFFFFFFFF;
178:         $packet->args[2] = "$sender invited $args[1] to your organization.";
179: 
180:         $this->chatBot->process_packet($packet);
181:     }
182:     
183:     /**
184:      * @HandlesCommand("testtowerattack")
185:      * @Matches("/^testtowerattack (clan|neutral|omni) (.+) (.+) (clan|neutral|omni) (.+) (.+) (\d+) (\d+)$/i")
186:      */
187:     public function testtowerattackCommand($message, $channel, $sender, $sendto, $args) {
188:         $eventObj = new stdClass;
189:         $eventObj->sender = -1;
190:         $eventObj->channel = "All Towers";
191:         $eventObj->message = "The $args[1] organization $args[2] just entered a state of war! $args[3] attacked the $args[4] organization $args[5]'s tower in $args[6] at location ($args[7],$args[8]).";
192:         $eventObj->type = 'towers';
193:         $this->eventManager->fireEvent($eventObj);
194:     }
195:     
196:     /**
197:      * @HandlesCommand("testtowervictory")
198:      * @Matches("/^testtowervictory (Clan|Neutral|Omni) (.+) (Clan|Neutral|Omni) (.+) (.+)$/i")
199:      */
200:     public function testtowervictoryCommand($message, $channel, $sender, $sendto, $args) {
201:         $packet = new stdClass;
202:         $packet->type = AOCP_GROUP_MESSAGE;
203:         $packet->args = array();
204:         $packet->args[0] = $this->chatBot->get_gid('tower battle outcome');
205:         $packet->args[1] = (int)0xFFFFFFFF;
206:         $packet->args[2] = "The $args[1] organization $args[2] attacked the $args[3] $args[4] at their base in $args[5]. The attackers won!!";
207: 
208:         $this->chatBot->process_packet($packet);
209:     }
210:     
211:     /**
212:      * @HandlesCommand("testos")
213:      * @Matches("/^testos (.+)$/i")
214:      */
215:     public function testosCommand($message, $channel, $sender, $sendto, $args) {
216:         $launcher = ucfirst(strtolower($args[1]));
217:     
218:         $packet = new stdClass;
219:         $packet->type = AOCP_GROUP_MESSAGE;
220:         $packet->args = array();
221:         $packet->args[0] = $this->chatBot->get_gid('org msg');
222:         $packet->args[1] = (int)0xFFFFFFFF;
223:         $packet->args[2] = "Blammo! $launcher has launched an orbital attack!";
224: 
225:         $this->chatBot->process_packet($packet);
226:     }
227: 
228:     /**
229:      * @HandlesCommand("testevent")
230:      * @Matches("/^testevent (.+)$/i")
231:      */
232:     public function testeventCommand($message, $channel, $sender, $sendto, $args) {
233:         $event = $args[1];
234:         
235:         list($instanceName, $methodName) = explode(".", $event);
236:         $instance = Registry::getInstance($instanceName);
237:         if ($instance == null) {
238:             $sendto->reply("Instance <highlight>$instanceName<end> does not exist.");
239:         } else if (!method_exists($instance, $methodName)) {
240:             $sendto->reply("Method <highlight>$methodName<end> does not exist on instance <highlight>$instanceName<end>.");
241:         } else {
242:             $this->eventManager->callEventHandler(null, $event);
243:             $sendto->reply("Event has been fired.");
244:         }
245:     }
246:     
247:     /**
248:      * @HandlesCommand("testcloaklower")
249:      * @Matches("/^testcloaklower$/i")
250:      */
251:     public function testcloaklowerCommand($message, $channel, $sender, $sendto, $args) {
252:         $packet = new stdClass;
253:         $packet->type = AOCP_GROUP_MESSAGE;
254:         $packet->args = array();
255:         $packet->args[0] = $this->chatBot->get_gid($this->chatBot->vars['my_guild']);
256:         $packet->args[1] = (int)0xFFFFFFFF;
257:         $packet->args[2] = "$sender turned the cloaking device in your city off.";
258: 
259:         $this->chatBot->process_packet($packet);
260:     }
261:     
262:     /**
263:      * @HandlesCommand("testcloakraise")
264:      * @Matches("/^testcloakraise$/i")
265:      */
266:     public function testcloakraiseCommand($message, $channel, $sender, $sendto, $args) {
267:         $packet = new stdClass;
268:         $packet->type = AOCP_GROUP_MESSAGE;
269:         $packet->args = array();
270:         $packet->args[0] = $this->chatBot->get_gid($this->chatBot->vars['my_guild']);
271:         $packet->args[1] = (int)0xFFFFFFFF;
272:         $packet->args[2] = "$sender turned the cloaking device in your city on.";
273: 
274:         $this->chatBot->process_packet($packet);
275:     }
276:     
277:     /**
278:      * @HandlesCommand("msginfo")
279:      * @Matches("/^msginfo (.+)$/i")
280:      */
281:     public function msginfoCommand($message, $channel, $sender, $sendto, $args) {
282:         $cmd = $args[1];
283: 
284:         $mockSendto = new MessageInfoCommandReply($sendto);
285:         $this->commandManager->process($channel, $cmd, $sender, $mockSendto);
286:     }
287: }
288: 
289: class MockCommandReply implements CommandReply {
290:     public function reply($msg) {
291:         //echo "got reply\n";
292:         //echo $msg . "\n";
293:     }
294: }
295: 
296: class MessageInfoCommandReply implements CommandReply {
297:     private $sendto;
298:     private $startTime;
299: 
300:     public function __construct($sendto) {
301:         $this->sendto = $sendto;
302:         $this->startTime = microtime(true);
303:     }
304: 
305:     public function reply($msg) {
306:         $endTime = microtime(true);
307:         if (!is_array($msg)) {
308:             $msg = array($msg);
309:         }
310:         
311:         forEach ($msg as $page) {
312:             $elapsed = round($endTime - $this->startTime, 4);
313:             $this->sendto->reply($page);
314:             $this->sendto->reply("Size: " . strlen($page));
315:             $this->sendto->reply("Time: $elapsed seconds");
316:         }
317:     }
318: }
Budabot 4 Docs API documentation generated by ApiGen