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;
  4: 
  5: /**
  6:  * @Instance
  7:  */
  8: class CommandAlias {
  9: 
 10:     /** @Inject */
 11:     public $db;
 12: 
 13:     /** @Inject */
 14:     public $chatBot;
 15: 
 16:     /** @Inject */
 17:     public $commandManager;
 18: 
 19:     /** @Logger */
 20:     public $logger;
 21: 
 22:     const ALIAS_HANDLER = "CommandAlias.process";
 23: 
 24:     /**
 25:      * @name: load
 26:      * @description: loads active aliases into memory to activate them
 27:      */
 28:     public function load() {
 29:         $this->logger->log('DEBUG', "Loading enabled command aliases");
 30: 
 31:         $data = $this->db->query("SELECT cmd, alias FROM cmd_alias_<myname> WHERE status = 1");
 32:         forEach ($data as $row) {
 33:             $this->activate($row->cmd, $row->alias);
 34:         }
 35:     }
 36: 
 37:     /**
 38:      * @name: register
 39:      * @description: Registers a command alias
 40:      */
 41:     public function register($module, $command, $alias, $status = 1) {
 42:         $module = strtoupper($module);
 43:         $command = strtolower($command);
 44:         $alias = strtolower($alias);
 45: 
 46:         $this->logger->log('DEBUG', "Registering alias: '{$alias}' for command: '$command'");
 47: 
 48:         $row = $this->get($alias);
 49:         if ($row !== null) {
 50:             // do not update an alias that a user created
 51:             if (!empty($row->module)) {
 52:                 $sql = "UPDATE cmd_alias_<myname> SET module = ?, cmd = ? WHERE alias = ?";
 53:                 $this->db->exec($sql, $module, $command, $alias);
 54:             }
 55:         } else {
 56:             $sql = "INSERT INTO cmd_alias_<myname> (module, cmd, alias, status) VALUES (?, ?, ?, ?)";
 57:             $this->db->exec($sql, $module, $command, $alias, $status);
 58:         }
 59:     }
 60: 
 61:     /**
 62:      * @name: activate
 63:      * @description: Activates a command alias
 64:      */
 65:     public function activate($command, $alias) {
 66:         $alias = strtolower($alias);
 67: 
 68:         $this->logger->log('DEBUG', "Activate Command Alias command:($command) alias:($alias)");
 69: 
 70:         $this->commandManager->activate('msg', self::ALIAS_HANDLER, $alias, 'all');
 71:         $this->commandManager->activate('priv', self::ALIAS_HANDLER, $alias, 'all');
 72:         $this->commandManager->activate('guild', self::ALIAS_HANDLER, $alias, 'all');
 73:     }
 74: 
 75:     /**
 76:      * @name: deactivate
 77:      * @description: Deactivates a command alias
 78:      */
 79:     public function deactivate($alias) {
 80:         $alias = strtolower($alias);
 81: 
 82:         $this->logger->log('DEBUG', "Deactivate Command Alias:($alias)");
 83: 
 84:         $this->commandManager->deactivate('msg', self::ALIAS_HANDLER, $alias);
 85:         $this->commandManager->deactivate('priv', self::ALIAS_HANDLER, $alias);
 86:         $this->commandManager->deactivate('guild', self::ALIAS_HANDLER, $alias);
 87:     }
 88: 
 89:     public function process($message, $channel, $sender, CommandReply $sendto) {
 90:         list($alias, $params) = explode(' ', $message, 2);
 91:         $alias = strtolower($alias);
 92: 
 93:         // Check if this is an alias for a command
 94:         $row = $this->get($alias);
 95:         if ($row === null) {
 96:             return false;
 97:         }
 98: 
 99:         $this->logger->log('DEBUG', "Command alias found command: '{$row->cmd}' alias: '{$row->alias}'");
100:         $cmd = $row->cmd;
101:         if ($params) {
102:             // count number of parameters and don't split more than that so that the
103:             // last parameter will have whatever is left
104: 
105:             // TODO: figure out highest numbered parameter and use that as $numMatches
106:             // otherwise this will break if the parameters do not include every number
107:             // from 1 to MAX -Tyrence
108:             preg_match_all("/{\\d+}/", $cmd, $matches);
109:             $numMatches = count(array_unique($matches[0]));
110:             if ($numMatches == 0) {
111:                 $cmd .= " {0}";
112:             }
113: 
114:             $aliasParams = explode(' ', $params, $numMatches);
115: 
116:             // add the entire param string as the {0} parameter
117:             array_unshift($aliasParams, $params);
118: 
119:             // replace parameter placeholders with their values
120:             for ($i = 0; $i < count($aliasParams); $i++) {
121:                 $cmd = str_replace('{' . $i . '}', $aliasParams[$i], $cmd);
122:             }
123:         }
124:         // if parameter placeholders still exist, then they did not pass enough parameters
125:         if (preg_match("/{\\d+}/", $cmd)) {
126:             return false;
127:         } else {
128:             $this->commandManager->process($channel, $cmd, $sender, $sendto);
129:         }
130:     }
131: 
132:     /**
133:      * @name: add
134:      * @description: Adds a command alias to the db
135:      */
136:     public function add($row) {
137:         $this->logger->log('DEBUG', "Adding alias: '{$alias}' for command: '$command'");
138: 
139:         $sql = "INSERT INTO cmd_alias_<myname> (module, cmd, alias, status) VALUES (?, ?, ?, ?)";
140:         return $this->db->exec($sql, $row->module, $row->cmd, $row->alias, $row->status);
141:     }
142: 
143:     /**
144:      * @name: update
145:      * @description: Updates a command alias in the db
146:      */
147:     public function update($row) {
148:         $this->logger->log('DEBUG', "Updating alias :($row->alias)");
149: 
150:         $sql = "UPDATE cmd_alias_<myname> SET module = ?, cmd = ?, status = ? WHERE alias = ?";
151:         return $this->db->exec($sql, $row->module, $row->cmd, $row->status, $row->alias);
152:     }
153: 
154:     public function get($alias) {
155:         $alias = strtolower($alias);
156: 
157:         $sql = "SELECT cmd, alias, module, status FROM cmd_alias_<myname> WHERE alias = ?";
158:         return $this->db->queryRow($sql, $alias);
159:     }
160: 
161:     public function getBaseCommandForAlias($alias) {
162:         $row = $this->get($alias);
163: 
164:         // if alias doesn't exist or is disabled
165:         if ($row === null || $row->status != 1) {
166:             return null;
167:         }
168:         list($cmd) = explode(' ', $row->cmd, 2);
169:         return $cmd;
170:     }
171: 
172:     public function findAliasesByCommand($command) {
173:         $sql = "SELECT cmd, alias, module, status FROM cmd_alias_<myname> WHERE cmd LIKE ?";
174:         return $this->db->query($sql, $command);
175:     }
176: 
177:     public function getEnabledAliases() {
178:         return $this->db->query("SELECT cmd, alias, module, status FROM cmd_alias_<myname> WHERE status = 1 ORDER BY alias ASC");
179:     }
180: }
181: 
Budabot 4 Docs API documentation generated by ApiGen