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: /**
  6:  * Authors: 
  7:  *  - Lucier (RK1)
  8:  *  - Tyrence (RK2)
  9:  *
 10:  * @Instance
 11:  *
 12:  * Commands this controller contains:
 13:  *  @DefineCommand(
 14:  *      command     = 'quote', 
 15:  *      accessLevel = 'all', 
 16:  *      description = 'Add/Remove/View Quotes', 
 17:  *      help        = 'quote.txt'
 18:  *  )
 19:  */
 20: class QuoteController {
 21: 
 22:     /**
 23:      * Name of the module.
 24:      * Set automatically by module loader.
 25:      */
 26:     public $moduleName;
 27:     
 28:     /** @Inject */
 29:     public $db;
 30:     
 31:     /** @Inject */
 32:     public $settingManager;
 33:     
 34:     /** @Inject */
 35:     public $accessManager;
 36: 
 37:     /** @Inject */
 38:     public $text;
 39:     
 40:     /** @Inject */
 41:     public $util;
 42:     
 43:     /**
 44:      * This handler is called on bot startup.
 45:      * @Setup
 46:      */
 47:     public function setup() {
 48:         $this->db->loadSQLFile($this->moduleName, "quote");
 49:     }
 50: 
 51:     /**
 52:      * @HandlesCommand("quote")
 53:      * @Matches("/^quote add (.+)$/si")
 54:      */
 55:     public function quoteAddCommand($message, $channel, $sender, $sendto, $args) {
 56:         $quoteMSG = trim($args[1]);
 57:         $row = $this->db->queryRow("SELECT * FROM `quote` WHERE `msg` LIKE ?", $quoteMSG);
 58:         if ($row !== null) {
 59:             $msg = "This quote has already been added as quote <highlight>$row->id<end>.";
 60:         } else {
 61:             if (strlen($quoteMSG) > 1000) {
 62:                 $msg = "This quote is too big.";
 63:             } else {
 64:                 $poster = $sender;
 65: 
 66:                 // nextId = maxId + 1
 67:                 $id = $this->getMaxId() + 1;
 68: 
 69:                 $this->db->exec("INSERT INTO `quote` (`id`, `poster`, `dt`, `msg`) VALUES (?, ?, ?, ?)", $id, $poster, time(), $quoteMSG);
 70:                 $msg = "Quote <highlight>$id<end> has been added.";
 71:             }
 72:         }
 73:         $sendto->reply($msg);
 74:     }
 75:     
 76:     /**
 77:      * @HandlesCommand("quote")
 78:      * @Matches("/^quote (rem|del|remove|delete) ([0-9]+)$/i")
 79:      */
 80:     public function quoteRemoveCommand($message, $channel, $sender, $sendto, $args) {
 81:         $id = $args[2];
 82:         $row = $this->db->queryRow("SELECT * FROM `quote` WHERE `id` = ?", $id);
 83: 
 84:         if ($row !== null) {
 85:             $poster = $row->poster;
 86: 
 87:             //only author or admin can delete.
 88:             if (($poster == $sender) || $this->accessManager->checkAccess($sender, 'moderator')) {
 89:                 $this->db->exec("DELETE FROM `quote` WHERE `id` = ?", $id);
 90:                 $msg = "This quote has been deleted.";
 91:             } else {
 92:                 $msg = "Only a moderator or $poster can delete this quote.";
 93:             }
 94:             
 95:             // re-number remaining quotes so there is no holes in the quote numbering
 96:             // since sqlite doesn't support ORDER BY on UPDATEs, we have to manually update each row
 97:             // in order to prevent duplicate key errors
 98:             $maxId = $this->getMaxId();
 99:             $currentId = $id + 1;
100:             
101:             while ($currentId <= $maxId ) {
102:                 $this->db->exec("UPDATE `quote` SET `id` = `id` - 1 WHERE `id` = ?", $currentId);
103:                 $currentId++;
104:             }
105:         } else {
106:             $msg = "Could not find this quote.  Already deleted?";
107:         }
108:         $sendto->reply($msg);
109:     }
110:     
111:     /**
112:      * @HandlesCommand("quote")
113:      * @Matches("/^quote search (.+)$/i")
114:      */
115:     public function quoteSearchCommand($message, $channel, $sender, $sendto, $args) {
116:         $search = $args[1];
117:         $searchParam = '%' . $search . '%';
118: 
119:         // Search for poster:
120:         $list = "";
121:         $data = $this->db->query("SELECT * FROM `quote` WHERE `poster` LIKE ?", $searchParam);
122:         forEach ($data as $row) {
123:             $list .= $this->text->makeChatcmd($row->id, "/tell <myname> quote $row->id") . ", ";
124:         }
125:         if ($list) {
126:             $msg .= "<tab>Quotes posted by <highlight>$search<end>: ";
127:             $msg .= substr($list, 0, strlen($list) - 2);
128:         }
129: 
130:         // Search inside quotes:
131:         $list = "";
132:         $data = $this->db->query("SELECT * FROM `quote` WHERE `msg` LIKE ?", $searchParam);
133:         forEach ($data as $row) {
134:             $list .= $this->text->makeChatcmd($row->id, "/tell <myname> quote $row->id") . ", ";
135:         }
136:         if ($list) {
137:             if ($msg) {
138:                 $msg .="\n\n";
139:             }
140:             $msg .= "<tab>Quotes that contain '<highlight>$search<end>': ";
141:             $msg .= substr($list, 0, strlen($list) - 2);
142:         }
143: 
144:         if ($msg) {
145:             $msg = $this->text->makeBlob("Results for: '$search'", $msg);
146:         } else {
147:             $msg = "Could not find any matches for this search.";
148:         }
149:         $sendto->reply($msg);
150:     }
151:     
152:     /**
153:      * @HandlesCommand("quote")
154:      * @Matches("/^quote ([0-9]+)$/i")
155:      */
156:     public function quoteShowCommand($message, $channel, $sender, $sendto, $args) {
157:         $id = $args[1];
158:         
159:         $result = $this->getQuoteInfo($id);
160:         
161:         if ($result == null) {
162:             $msg = "No quote found with ID <highlight>$id<end>.";
163:         } else {
164:             $msg = $result;
165:         }
166:         $sendto->reply($msg);
167:     }
168:     
169:     /**
170:      * @HandlesCommand("quote")
171:      * @Matches("/^quote$/i")
172:      */
173:     public function quoteShowRandomCommand($message, $channel, $sender, $sendto, $args) {
174:         // choose a random quote to show
175:         $result = $this->getQuoteInfo(null);
176:         
177:         if ($result == null) {
178:             $msg = "There are no quotes to show.";
179:         } else {
180:             $msg = $result;
181:         }
182:         $sendto->reply($msg);
183:     }
184:     
185:     public function getMaxId() {
186:         $row = $this->db->queryRow("SELECT COALESCE(MAX(id), 0) AS max_id FROM `quote`");
187:         return $row->max_id;
188:     }
189: 
190:     public function getQuoteInfo($id = null) {
191:         $count = $this->getMaxId();
192: 
193:         if ($count == 0) {
194:             return null;
195:         }
196: 
197:         if ($id == null) {
198:             $id = rand(1, $count);
199:         }
200: 
201:         $row = $this->db->queryRow("SELECT * FROM `quote` WHERE `id` = ?", $id);
202:         if ($row === null) {
203:             return null;
204:         }
205: 
206:         $poster = $row->poster;
207:         $quoteMSG = $row->msg;
208: 
209:         $msg = "ID: <highlight>$id<end> of $count\n";
210:         $msg .= "Poster: <highlight>$poster<end>\n";
211:         $msg .= "Date: <highlight>" . $this->util->date($row->dt) . "<end>\n";
212:         $msg .= "Quote: <highlight>$quoteMSG<end>\n\n";
213: 
214:         $msg .= "<header2>Quotes posted by <highlight>$poster<end>\n";
215:         $data = $this->db->query("SELECT * FROM `quote` WHERE `poster` = ?", $poster);
216:         $list = "";
217:         forEach ($data as $row) {
218:             $list .= $this->text->makeChatcmd($row->id, "/tell <myname> quote $row->id") . ", ";
219:         }
220:         $msg .= substr($list, 0, strlen($list) - 2);
221: 
222:         return $this->text->makeBlob("Quote", $msg).': "'.$quoteMSG.'"';
223:     }
224: }
225: 
Budabot 4 Docs API documentation generated by ApiGen