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 stdClass;
  6: use DOMDocument;
  7: 
  8: /**
  9:  * Authors: 
 10:  *  - Tyrence (RK2)
 11:  *
 12:  * @Instance
 13:  *
 14:  * Commands this controller contains:
 15:  *  @DefineCommand(
 16:  *      command     = 'aou', 
 17:  *      accessLevel = 'all', 
 18:  *      description = 'Search for or view a guide from AO-Universe.com', 
 19:  *      help        = 'aou.txt'
 20:  *  )
 21:  */
 22: class AOUController {
 23: 
 24:     /**
 25:      * Name of the module.
 26:      * Set automatically by module loader.
 27:      */
 28:     public $moduleName;
 29: 
 30:     /** @Inject */
 31:     public $text;
 32:     
 33:     /** @Inject */
 34:     public $itemsController;
 35: 
 36:     /** @Inject */
 37:     public $http;
 38: 
 39:     const AOU_URL = "https://www.ao-universe.com/mobile/parser.php?bot=budabot";
 40:     
 41:     /**
 42:      * View an AO-U guide.
 43:      *
 44:      * @HandlesCommand("aou")
 45:      * @Matches("/^aou (\d+)$/i")
 46:      */
 47:     public function aouView($message, $channel, $sender, $sendto, $args) {
 48:         $guideid = $args[1];
 49: 
 50:         $params = array(
 51:             'mode' => 'view',
 52:             'id' => $guideid
 53:         );
 54:         $guide = $this->http->get(self::AOU_URL)->withQueryParams($params)->waitAndReturnResponse()->body;
 55: 
 56:         $dom = new DOMDocument;
 57:         $dom->loadXML($guide);
 58:         
 59:         if ($dom->getElementsByTagName('error')->length > 0) {
 60:             $msg = "An error occurred while trying to retrieve AOU guide with id <highlight>$guideid<end>: " .
 61:                 $dom->getElementsByTagName('text')->item(0)->nodeValue;
 62:             $sendto->reply($msg);
 63:             return;
 64:         }
 65: 
 66:         $content = $dom->getElementsByTagName('content')->item(0);
 67:         if ($content == null) {
 68:             $msg = "Error retrieving guide <highlight>$guideid<end> from AO-Universe.com";
 69:         } else {
 70:             $title = $content->getElementsByTagName('name')->item(0)->nodeValue;
 71: 
 72:             $blob = '';
 73:             $blob .= $this->text->makeChatcmd("Guide on AO-Universe.com", "/start http://www.ao-universe.com/main.php?site=knowledge&id={$guideid}") . "\n\n";
 74: 
 75:             $blob .= "Update: <highlight>" . $content->getElementsByTagName('update')->item(0)->nodeValue . "<end>\n";
 76:             $blob .= "Profession: <highlight>" . $content->getElementsByTagName('class')->item(0)->nodeValue . "<end>\n";
 77:             $blob .= "Faction: <highlight>" . $content->getElementsByTagName('faction')->item(0)->nodeValue . "<end>\n";
 78:             $blob .= "Level: <highlight>" . $content->getElementsByTagName('level')->item(0)->nodeValue . "<end>\n";
 79:             $blob .= "Author: <highlight>" . $this->processInput($content->getElementsByTagName('author')->item(0)->nodeValue) . "<end>\n\n";
 80: 
 81:             $blob .= $this->processInput($content->getElementsByTagName('text')->item(0)->nodeValue);
 82: 
 83:             $blob .= "\n\n<highlight>Powered by<end> " . $this->text->makeChatcmd("AO-Universe.com", "/start http://www.ao-universe.com");
 84: 
 85:             $msg = $this->text->makeBlob($title, $blob);
 86:         }
 87:         $sendto->reply($msg);
 88:     }
 89:     
 90:     /**
 91:      * Search for an AO-U guide and include guides that have the search terms in the guide text.
 92:      *
 93:      * @HandlesCommand("aou")
 94:      * @Matches("/^aou all (.+)$/i")
 95:      */
 96:     public function aouAllSearch($message, $channel, $sender, $sendto, $args) {
 97:         $search = $args[1];
 98: 
 99:         $msg = $this->searchForAOUGuide($search, true);
100:         $sendto->reply($msg);
101:     }
102:     
103:     /**
104:      * Search for an AO-U guide.
105:      *
106:      * @HandlesCommand("aou")
107:      * @Matches("/^aou (.+)$/i")
108:      */
109:     public function aouSearch($message, $channel, $sender, $sendto, $args) {
110:         $search = $args[1];
111: 
112:         $msg = $this->searchForAOUGuide($search, false);
113:         $sendto->reply($msg);
114:     }
115:     
116:     public function searchForAOUGuide($search, $searchGuideText) {
117:         $searchTerms = explode(" ", $search);
118:     
119:         $params = array(
120:             'mode' => 'search',
121:             'search' => $search
122:         );
123:         $results = $this->http->get(self::AOU_URL)->withQueryParams($params)->waitAndReturnResponse()->body;
124: 
125:         $dom = new DOMDocument;
126:         $dom->loadXML($results);
127:         
128:         $sections = $dom->getElementsByTagName('section');
129:         $blob = '';
130:         $count = 0;
131:         forEach ($sections as $section) {
132:             $category = $this->getSearchResultCategory($section);
133:         
134:             $guides = $section->getElementsByTagName('guide');
135:             $tempBlob = '';
136:             $found = false;
137:             forEach ($guides as $guide) {
138:                 $guideObj = $this->getGuideObject($guide);
139:                 // since aou returns guides that have keywords in the guide body, we filter the results again
140:                 // to only include guides that contain the keywords in the category, name, or description
141:                 if ($searchGuideText || $this->striposarray($category . ' ' . $guideObj->name . ' ' . $guideObj->description, $searchTerms)) {
142:                     $count++;
143:                     $tempBlob .= '  ' . $this->text->makeChatcmd("$guideObj->name", "/tell <myname> aou $guideObj->id") . " - " . $guideObj->description . "\n";
144:                     $found = true;
145:                 }
146:             }
147:             
148:             if ($found) {
149:                 $blob .= "<pagebreak><header2>" . $category . "<end>\n";
150:                 $blob .= $tempBlob;
151:                 $blob .= "\n";
152:             }
153:         }
154: 
155:         $blob .= "\n<highlight>Powered by<end> " . $this->text->makeChatcmd("AO-Universe.com", "/start http://www.ao-universe.com");
156: 
157:         if ($count > 0) {
158:             if ($searchGuideText) {
159:                 $title = "All AO-U Guides containing '$search' ($count)";
160:             } else {
161:                 $title = "AO-U Guides containing '$search' ($count)";
162:             }
163:             $msg = $this->text->makeBlob($title, $blob);
164:         } else {
165:             $msg = "Could not find any guides containing: '$search'.";
166:             if (!$searchGuideText) {
167:                 $msg .= " Try including all results with <highlight>!aou all $search<end>.";
168:             }
169:         }
170:         return $msg;
171:     }
172:     
173:     private function striposarray($haystack, $needles) {
174:         forEach ($needles as $needle) {
175:             if (stripos($haystack, $needle) === false) {
176:                 return false;
177:             }
178:         }
179:         return true;
180:     }
181:     
182:     private function getSearchResultCategory($section) {
183:         $folders = $section->getElementsByTagName('folder');
184:         $output = array();
185:         forEach ($folders as $folder) {
186:             $output []= $folder->getElementsByTagName('name')->item(0)->nodeValue;
187:         }
188:         return implode(" - ", array_reverse($output));
189:     }
190:     
191:     private function getGuideObject($guide) {
192:         $obj = new stdClass;
193:         $obj->id = $guide->getElementsByTagName('id')->item(0)->nodeValue;
194:         $obj->name = $guide->getElementsByTagName('name')->item(0)->nodeValue;
195:         $obj->description = $guide->getElementsByTagName('desc')->item(0)->nodeValue;
196:         return $obj;
197:     }
198:     
199:     private function replaceItem($arr) {
200:         $type = $arr[1];
201:         $id = $arr[3];
202:         
203:         $output = '';
204: 
205:         $row = $this->itemsController->findById($id);
206:         if ($row !== null) {
207:             $output = $this->generateItemMarkup($type, $row);
208:         } else {
209:             $output = $id;
210:         }
211:         return $output;
212:     }
213:     
214:     private function replaceWaypoint($arr) {
215:         $label = $arr[2];
216:         $params = explode(" ", $arr[1]);
217:         forEach ($params as $param) {
218:             list($name, $value) = explode("=", $param);
219:             $$name = $value;
220:         }
221:         
222:         return $this->text->makeChatcmd($label . " ({$x}x{$y})", "/waypoint $x $y $pf");
223:     }
224:     
225:     private function replaceGuideLinks($arr) {
226:         $url = $arr[2];
227:         $label = $arr[3];
228:         
229:         if (preg_match("/pid=(\\d+)/", $url, $idArray)) {
230:             return $this->text->makeChatcmd($label, "/tell <myname> aou " . $idArray[1]);
231:         } else {
232:             return $this->text->makeChatcmd($label, "/start $url");
233:         }
234:     }
235:     
236:     private function processInput($input) {
237:         $input = preg_replace_callback("/\\[(item|itemname|itemicon)( nolink)?\\](\\d+)\\[\\/(item|itemname|itemicon)\\]/i", array($this, 'replaceItem'), $input);
238:         $input = preg_replace_callback("/\\[waypoint ([^\\]]+)\\]([^\\]]*)\\[\\/waypoint\\]/", array($this, 'replaceWaypoint'), $input);
239:         $input = preg_replace_callback("/\\[(localurl|url)=([^ \\]]+)\\]([^\\[]+)\\[\\/(localurl|url)\\]/", array($this, 'replaceGuideLinks'), $input);
240:         $input = preg_replace("/\\[img\\]([^\\[]+)\\[\\/img\\]/", "-image-", $input);
241:         $input = preg_replace("/\\[color=#([0-9A-F]+)\\]([^\\[]+)\\[\\/color\\]/", "<font color=#\\1>\\2</font>", $input);
242:         $input = preg_replace("/\\[color=([^\\]]+)\\]([^\\[]+)\\[\\/color\\]/", "<\\1>\\2<end>", $input);
243:         $input = str_replace("[center]", "<center>", $input);
244:         $input = str_replace("[/center]", "</center>", $input);
245:         $input = str_replace("[i]", "<i>", $input);
246:         $input = str_replace("[/i]", "</i>", $input);
247:         $input = str_replace("[b]", "<highlight>", $input);
248:         $input = str_replace("[/b]", "<end>", $input);
249: 
250:         $pattern = "/(\\[[^\\]]+\\])/";
251:         $matches = preg_split($pattern, $input, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
252: 
253:         $output = '';
254:         forEach ($matches as $match) {
255:             $output .= $this->processTag($match);
256:         }
257: 
258:         return $output;
259:     }
260:     
261:     private function processTag($tag) {
262:         switch ($tag) {
263:             case "[ts_ts]":
264:                 return " + ";
265:             case "[ts_ts2]":
266:                 return " = ";
267:             case "[cttd]":
268:                 return " | ";
269:             case "[cttr]":
270:             case "[br]":
271:                 return "\n";
272:         }
273: 
274:         if ($tag[0] == '[') {
275:             return "";
276:         }
277: 
278:         return $tag;
279:     }
280:     
281:     private function generateItemMarkup($type, $obj) {
282:         $output = '';
283:         if ($type == "item" || $type == "itemicon") {
284:             $output .= $this->text->makeImage($obj->icon);
285:         }
286:         
287:         if ($type == "item" || $type == "itemname") {
288:             $output .= $this->text->makeItem($obj->lowid, $obj->highid, $obj->highql, $obj->name);
289:         }
290: 
291:         return $output;
292:     }
293: }
294: 
Budabot 4 Docs API documentation generated by ApiGen