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 Exception;
  6: 
  7: /**
  8:  * Authors:
  9:  *  - Tyrence
 10:  *
 11:  * Based on a module written by Captainzero (RK1) of the same name for an earlier version of Budabot
 12:  *
 13:  * @Instance
 14:  *
 15:  * Commands this controller contains:
 16:  *  @DefineCommand(
 17:  *      command     = 'recipe',
 18:  *      accessLevel = 'all',
 19:  *      description = 'Search for a recipe',
 20:  *      help        = 'recipe.txt'
 21:  *  )
 22:  */
 23: class RecipeController {
 24: 
 25:     /**
 26:      * Name of the module.
 27:      * Set automatically by module loader.
 28:      */
 29:     public $moduleName;
 30: 
 31:     /** @Inject */
 32:     public $db;
 33: 
 34:     /** @Inject */
 35:     public $util;
 36: 
 37:     /** @Inject */
 38:     public $text;
 39:     
 40:     /** @Inject */
 41:     public $itemsController;
 42: 
 43:     private $path;
 44: 
 45:     /**
 46:      * @Event("connect")
 47:      * @Description("Initializes the recipe database")
 48:      * @DefaultStatus("1")
 49:      * 
 50:      * This is a Event("connect") instead of Setup since it depends on the items db being loaded
 51:      */
 52:     public function connectEvent() {
 53:         $this->db->loadSQLFile($this->moduleName, "recipes", true);
 54: 
 55:         $this->path = getcwd() . "/modules/" . $this->moduleName . "/recipes/";
 56:         if ($handle = opendir($this->path)) {
 57:             while (false !== ($fileName = readdir($handle))) {
 58:                 // if file has the correct extension, load recipe into database
 59:                 if (preg_match("/(\d+)\.txt/", $fileName, $args)) {
 60:                     $id = $args[1];
 61:                     $lines = file($this->path . $fileName);
 62:                     $name = substr(trim(array_shift($lines)), 6);
 63:                     $author = substr(trim(array_shift($lines)), 8);
 64:                     $data = implode("", $lines);
 65:                     $this->db->exec("INSERT INTO recipes (id, name, author, recipe) VALUES (?, ?, ?, ?)", $id, $name, $author, $data);
 66:                 } else if (preg_match("/(\d+)\.json/", $fileName, $args)) {
 67:                     $recipe = json_decode(file_get_contents($this->path . $fileName));
 68:                     if ($recipe === null) {
 69:                         throw new Exception("Could not read '$fileName', invalid JSON");
 70:                     }
 71: 
 72:                     $id = $args[1];
 73:                     $name = $recipe->name;
 74:                     $author = $recipe->author;
 75:                     $items = array();
 76:                     forEach($recipe->items as $item) {
 77:                         $dbItem = $this->itemsController->findById($item->item_id);
 78:                         if ($dbItem === null) {
 79:                             throw Exception("Could not find item '{$item->item_id}'");
 80:                         }
 81:                         $items[$item->alias] = $dbItem;
 82:                         $items[$item->alias]->ql = $item->ql;
 83:                     }
 84: 
 85:                     $data = "#C16------------------------------\n";
 86:                     $data .= "#C12Ingredients #C20\n";
 87:                     $data .= "#C16------------------------------\n\n";
 88:                     $ingredients = $items;
 89:                     forEach($recipe->steps as $step) {
 90:                         unset($ingredients[$step->result]);
 91:                     }
 92:                     forEach($ingredients as $ingredient) {
 93:                         $data .= $this->text->makeImage($ingredient->icon) . "\n";
 94:                         $data .= $this->text->makeItem($ingredient->lowid, $ingredient->highid, $ingredient->ql, $ingredient->name) . "\n\n\n";
 95:                     }
 96: 
 97:                     $data .= "#C16------------------------------\n";
 98:                     $data .= "#C12Recipe #C16\n";
 99:                     $data .= "#C16------------------------------#C20\n\n";
100:                     forEach($recipe->steps as $step) {
101:                         $source = $items[$step->source];
102:                         $target = $items[$step->target];
103:                         $result = $items[$step->result];
104:                         $data .= $source->name . "\n";
105:                         $data .= "#C15+#C20" . "\n";
106:                         $data .= $target->name . "\n";
107:                         $data .= "#C15=#C20" . "\n";
108:                         $data .= $this->text->makeImage($result->icon) . "\n";
109:                         $data .= $this->text->makeItem($result->lowid, $result->highid, $result->ql, $result->name) . "\n";
110:                         if ($step->skills) {
111:                             $data .= "#C16Skills: | {$step->skills} |#C20\n";
112:                         }
113:                         $data .= "\n\n";
114:                     }
115: 
116:                     $this->db->exec("INSERT INTO recipes (id, name, author, recipe) VALUES (?, ?, ?, ?)", $id, $name, $author, $data);
117:                 }
118:             }
119:             closedir($handle);
120:         } else {
121:             throw new Exception("Could not open '$this->path' for loading recipes");
122:         }
123:     }
124:     
125:     /**
126:      * @HandlesCommand("recipe")
127:      * @Matches("/^recipe ([0-9]+)$/i")
128:      */
129:     public function recipeShowCommand($message, $channel, $sender, $sendto, $args) {
130:         $id = $args[1];
131:         
132:         $row = $this->db->queryRow("SELECT * FROM recipes WHERE id = ?", $id);
133: 
134:         if ($row === null) {
135:             $msg = "Could not find recipe with id <highlight>$id<end>.";
136:         } else {
137:             $msg = $this->createRecipeBlob($row);
138:         }
139:         $sendto->reply($msg);
140:     }
141:     
142:     /**
143:      * @HandlesCommand("recipe")
144:      * @Matches("/^recipe (.+)$/i")
145:      */
146:     public function recipeSearchCommand($message, $channel, $sender, $sendto, $args) {
147:         if (preg_match('|<a href="itemref://(\d+)/(\d+)/(\d+)">([^<]+)</a>|', $args[1], $matches)) {
148:             $lowId = $matches[1];
149:             $search = $matches[4];
150:             
151:             $data = $this->db->query("SELECT * FROM recipes WHERE recipe LIKE ? OR recipe LIKE ? ORDER BY name ASC", $search, "%" . $lowId . "%");
152:         } else {
153:             $search = $args[1];
154:             
155:             list($query, $queryParams) = $this->util->generateQueryFromParams(explode(" ", $search), "recipe");
156:             $data = $this->db->query("SELECT * FROM recipes WHERE $query ORDER BY name ASC", $queryParams);
157:         }
158:         
159:         $count = count($data);
160: 
161:         if ($count == 0) {
162:             $msg = "Could not find any recipes matching your search criteria.";
163:         } else if ($count == 1) {
164:             $msg = $this->createRecipeBlob($data[0]);
165:         } else {
166:             $blob = '';
167:             forEach ($data as $row) {
168:                 $blob .= $this->text->makeChatcmd($row->name, "/tell <myname> recipe $row->id") . "\n";
169:             }
170: 
171:             $msg = $this->text->makeBlob("Recipes matching '$search' ($count)", $blob);
172:         }
173: 
174:         $sendto->reply($msg);
175:     }
176:     
177:     public function formatRecipeText($input) {
178:         $input = str_replace("\\n", "\n", $input);
179:         $input = preg_replace_callback('/#L "([^"]+)" "([0-9]+)"/', array($this, 'replaceItem'), $input);
180:         $input = preg_replace('/#L "([^"]+)" "([^"]+)"/', "<a href='chatcmd://\\2'>\\1</a>", $input);
181:         
182:         // we can't use <myname> in the sql since that will get converted on load,
183:         // and we need to wait to convert until display time due to the possibility
184:         // of several bots sharing the same db
185:         $input = str_replace("{myname}", "<myname>", $input);
186: 
187:         $input = str_replace("#C09","</font><font color=#FFFFFF>", $input);
188:         $input = str_replace("#C12","</font><font color=#FF0000>", $input);
189:         $input = str_replace("#C13","</font><font color=#FFFFFF>", $input);
190:         $input = str_replace("#C14","</font><font color=#FFFFFF>", $input);
191:         $input = str_replace("#C15","</font><font color=#FFFFFF>", $input);
192:         $input = str_replace("#C16","</font><font color=#FFFF00>", $input);
193:         $input = str_replace("#C18","</font><font color=#AAFF00>", $input);
194:         $input = str_replace("#C20","</font><font color=#009B00>", $input);
195:             
196:         return $input;
197:     }
198:     
199:     public function createRecipeBlob($row) {
200:         $recipe_name = $row->name;
201:         $author = empty($row->author) ? "Unknown" : $row->author;
202: 
203:         $recipeText = "Recipe Id: <highlight>$row->id<end>\n"; 
204:         $recipeText .= "Author: <highlight>$author<end>\n\n";
205:         $recipeText .= $this->formatRecipeText($row->recipe);
206: 
207:         return $this->text->makeBlob("Recipe for $recipe_name", $recipeText);
208:     }
209: 
210:     private function replaceItem($arr) {
211:         $id = $arr[2];
212:         $row = $this->itemsController->findById($id);
213:         if ($row !== null) {
214:             $output = $this->text->makeItem($row->lowid, $row->highid, $row->highql, $row->name);
215:         } else {
216:             $output = "#L \"{$arr[1]}\" \"/tell <myname> itemid {$arr[2]}\"";
217:         }
218:         return $output;
219:     }
220: }
221: 
222: 
Budabot 4 Docs API documentation generated by ApiGen