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\Modules;
  4: 
  5: use ReflectionClass;
  6: use Budabot\Core\Registry;
  7: 
  8: /**
  9:  * @Instance
 10:  */
 11: class ConfigController {
 12: 
 13:     /**
 14:      * Name of the module.
 15:      * Set automatically by module loader.
 16:      */
 17:     public $moduleName;
 18: 
 19:     /** @Inject */
 20:     public $text;
 21: 
 22:     /** @Inject */
 23:     public $db;
 24: 
 25:     /** @Inject */
 26:     public $commandManager;
 27: 
 28:     /** @Inject */
 29:     public $eventManager;
 30: 
 31:     /** @Inject */
 32:     public $subcommandManager;
 33: 
 34:     /** @Inject */
 35:     public $commandAlias;
 36: 
 37:     /** @Inject */
 38:     public $helpManager;
 39: 
 40:     /** @Inject */
 41:     public $settingManager;
 42:     
 43:     /** @Inject */
 44:     public $accessManager;
 45:     
 46:     /** @Logger */
 47:     public $logger;
 48: 
 49:     /**
 50:      * @Setup
 51:      * This handler is called on bot startup.
 52:      */
 53:     public function setup() {
 54: 
 55:         // construct list of command handlers
 56:         $filename = array();
 57:         $reflectedClass = new ReflectionClass($this);
 58:         $className = Registry::formatName(get_class($this));
 59:         forEach ($reflectedClass->getMethods() as $reflectedMethod) {
 60:             if (preg_match('/command$/i', $reflectedMethod->name)) {
 61:                 $filename []= "{$className}.{$reflectedMethod->name}";
 62:             }
 63:         }
 64:         $filename = implode(',', $filename);
 65: 
 66:         $this->commandManager->activate("msg", $filename, "config", "mod");
 67:         $this->commandManager->activate("guild", $filename, "config", "mod");
 68:         $this->commandManager->activate("priv", $filename, "config", "mod");
 69: 
 70:         $this->helpManager->register($this->moduleName, "config", "config.txt", "mod", "Configure Commands/Events");
 71:     }
 72: 
 73:     /**
 74:      * This command handler lists list of modules which can be configured.
 75:      * Note: This handler has not been not registered, only activated.
 76:      *
 77:      * @Matches("/^config$/i")
 78:      */
 79:     public function configCommand($message, $channel, $sender, $sendto, $args) {
 80:         $blob = 
 81:             "Org Commands - " .
 82:                 $this->text->makeChatcmd('Enable All', '/tell <myname> config cmd enable guild') . " " .
 83:                 $this->text->makeChatcmd('Disable All', '/tell <myname> config cmd disable guild') . "\n" .
 84:             "Private Channel Commands - " .
 85:                 $this->text->makeChatcmd('Enable All', '/tell <myname> config cmd enable priv') . " " .
 86:                 $this->text->makeChatcmd('Disable All', '/tell <myname> config cmd disable priv') . "\n" .
 87:             "Private Message Commands - " .
 88:                 $this->text->makeChatcmd('Enable All', '/tell <myname> config cmd enable msg') . " " .
 89:                 $this->text->makeChatcmd('Disable All', '/tell <myname> config cmd disable msg') . "\n" .
 90:             "ALL Commands - " .
 91:                 $this->text->makeChatcmd('Enable All', '/tell <myname> config cmd enable all') . " " .
 92:                 $this->text->makeChatcmd('Disable All', '/tell <myname> config cmd disable all') . "\n\n\n";
 93:     
 94:         $sql = "
 95:             SELECT
 96:                 module,
 97:                 SUM(CASE WHEN status = 1 THEN 1 ELSE 0 END) count_enabled,
 98:                 SUM(CASE WHEN status = 0 THEN 1 ELSE 0 END) count_disabled
 99:             FROM
100:                 (SELECT module, status FROM cmdcfg_<myname> WHERE `cmdevent` = 'cmd'
101:                 UNION
102:                 SELECT module, status FROM eventcfg_<myname>
103:                 UNION
104:                 SELECT module, 2 FROM settings_<myname>) t
105:             GROUP BY
106:                 module
107:             ORDER BY
108:                 module ASC";
109:     
110:         $data = $this->db->query($sql);
111:         $count = count($data);
112:         forEach ($data as $row) {
113:             if ($row->count_enabled > 0 && $row->count_disabled > 0) {
114:                 $a = "(<yellow>Partial<end>)";
115:             } else if ($row->count_disabled == 0) {
116:                 $a = "(<green>Running<end>)";
117:             } else {
118:                 $a = "(<red>Disabled<end>)";
119:             }
120:     
121:             $c = "(" . $this->text->makeChatcmd("Configure", "/tell <myname> config $row->module") . ")";
122:     
123:             $on = $this->text->makeChatcmd("On", "/tell <myname> config mod $row->module enable all");
124:             $off = $this->text->makeChatcmd("Off", "/tell <myname> config mod $row->module disable all");
125:             $blob .= strtoupper($row->module)." $a ($on/$off) $c\n";
126:         }
127:     
128:         $msg = $this->text->makeBlob("Module Config ($count)", $blob);
129:         $sendto->reply($msg);
130:     }
131: 
132:     /**
133:      * This command handler turns a channel of all modules on or off.
134:      * Note: This handler has not been not registered, only activated.
135:      *
136:      * @Matches("/^config cmd (enable|disable) (all|guild|priv|msg)$/i")
137:      */
138:     public function toggleChannelOfAllModulesCommand($message, $channel, $sender, $sendto, $args) {
139:         $status = ($args[1] == "enable" ? 1 : 0);
140:         $typeSql = ($args[2] == "all" ? "`type` = 'guild' OR `type` = 'priv' OR `type` = 'msg'" : "`type` = '{$args[2]}'");
141:     
142:         $sql = "SELECT type, file, cmd, admin FROM cmdcfg_<myname> WHERE `cmdevent` = 'cmd' AND ($typeSql)";
143:         $data = $this->db->query($sql);
144:         forEach ($data as $row) {
145:             if (!$this->accessManager->checkAccess($sender, $row->admin)) {
146:                 continue;
147:             }
148:             if ($status == 1) {
149:                 $this->commandManager->activate($row->type, $row->file, $row->cmd, $row->admin);
150:             } else {
151:                 $this->commandManager->deactivate($row->type, $row->file, $row->cmd);
152:             }
153:         }
154:     
155:         $sql = "UPDATE cmdcfg_<myname> SET `status` = $status WHERE (`cmdevent` = 'cmd' OR `cmdevent` = 'subcmd') AND ($typeSql)";
156:         $this->db->exec($sql);
157:     
158:         $sendto->reply("Commands updated successfully.");
159:     }
160: 
161:     /**
162:      * This command handler turns a channel of a single command, subcommand,
163:      * module or event on or off.
164:      * Note: This handler has not been not registered, only activated.
165:      *
166:      * @Matches("/^config (subcmd|mod|cmd|event) (.+) (enable|disable) (priv|msg|guild|all)$/i")
167:      */
168:     public function toggleChannelCommand($message, $channel, $sender, $sendto, $args) {
169:         if ($args[1] == "event") {
170:             $temp = explode(" ", $args[2]);
171:             $event_type = strtolower($temp[0]);
172:             $file = $temp[1];
173:         } else if ($args[1] == 'cmd' || $args[1] == 'subcmd') {
174:             $cmd = strtolower($args[2]);
175:             $type = $args[4];
176:         } else { // $args[1] == 'mod'
177:             $module = strtoupper($args[2]);
178:             $type = $args[4];
179:         }
180:     
181:         if ($args[3] == "enable") {
182:             $status = 1;
183:         } else {
184:             $status = 0;
185:         }
186:     
187:         if ($args[1] == "mod" && $type == "all") {
188:             $sql = "SELECT status, type, file, cmd, admin, cmdevent FROM cmdcfg_<myname> WHERE `module` = '$module'
189:                         UNION
190:                     SELECT status, type, file, '' AS cmd, '' AS admin, 'event' AS cmdevent FROM eventcfg_<myname> WHERE `module` = '$module' AND `type` <> 'setup'";
191:         } else if ($args[1] == "mod" && $type != "all") {
192:             $sql = "SELECT status, type, file, cmd, admin, cmdevent FROM cmdcfg_<myname> WHERE `module` = '$module' AND `type` = '$type'
193:                         UNION
194:                     SELECT status, type, file, cmd AS '', admin AS '', cmdevent AS 'event' FROM eventcfg_<myname> WHERE `module` = '$module' AND `type` = '$event_type' AND `type` <> 'setup'";
195:         } else if ($args[1] == "cmd" && $type != "all") {
196:             $sql = "SELECT * FROM cmdcfg_<myname> WHERE `cmd` = '$cmd' AND `type` = '$type' AND `cmdevent` = 'cmd'";
197:         } else if ($args[1] == "cmd" && $type == "all") {
198:             $sql = "SELECT * FROM cmdcfg_<myname> WHERE `cmd` = '$cmd' AND `cmdevent` = 'cmd'";
199:         } else if ($args[1] == "subcmd" && $type != "all") {
200:             $sql = "SELECT * FROM cmdcfg_<myname> WHERE `cmd` = '$cmd' AND `type` = '$type' AND `cmdevent` = 'subcmd'";
201:         } else if ($args[1] == "subcmd" && $type == "all") {
202:             $sql = "SELECT * FROM cmdcfg_<myname> WHERE `cmd` = '$cmd' AND `cmdevent` = 'subcmd'";
203:         } else if ($args[1] == "event" && $file != "") {
204:             $sql = "SELECT *, 'event' AS cmdevent FROM eventcfg_<myname> WHERE `file` = '$file' AND `type` = '$event_type' AND `type` <> 'setup'";
205:         } else {
206:             $syntax_error = true;
207:             return;
208:         }
209:     
210:         $data = $this->db->query($sql);
211:         
212:         if ($args[1] == 'cmd' || $args[1] == 'subcmd') {
213:             if (!$this->checkCommandAccessLevels($data, $sender)) {
214:                 $msg = "You do not have the required access level to change this command.";
215:                 $sendto->reply($msg);
216:                 return;
217:             }
218:         }
219:     
220:         if (count($data) == 0) {
221:             if ($args[1] == "mod" && $type == "all") {
222:                 $msg = "Could not find Module <highlight>$module<end>.";
223:             } else if ($args[1] == "mod" && $type != "all") {
224:                 $msg = "Could not find module <highlight>$module<end> for channel <highlight>$type<end>.";
225:             } else if ($args[1] == "cmd" && $type != "all") {
226:                 $msg = "Could not find command <highlight>$cmd<end> for channel <highlight>$type<end>.";
227:             } else if ($args[1] == "cmd" && $type == "all") {
228:                 $msg = "Could not find command <highlight>$cmd<end>.";
229:             } else if ($args[1] == "subcmd" && $type != "all") {
230:                 $msg = "Could not find subcommand <highlight>$cmd<end> for channel <highlight>$type<end>.";
231:             } else if ($args[1] == "subcmd" && $type == "all") {
232:                 $msg = "Could not find subcommand <highlight>$cmd<end>.";
233:             } else if ($args[1] == "event" && $file != "") {
234:                 $msg = "Could not find event <highlight>$event_type<end> for handler <highlight>$file<end>.";
235:             }
236:             $sendto->reply($msg);
237:             return;
238:         }
239:     
240:         if ($args[1] == "mod" && $type == "all") {
241:             $msg = "Updated status of module <highlight>$module<end> to <highlight>".$args[3]."d<end>.";
242:         } else if ($args[1] == "mod" && $type != "all") {
243:             $msg = "Updated status of module <highlight>$module<end> in channel <highlight>$type<end> to <highlight>".$args[3]."d<end>.";
244:         } else if ($args[1] == "cmd" && $type != "all") {
245:             $msg = "Updated status of command <highlight>$cmd<end> to <highlight>".$args[3]."d<end> in channel <highlight>$type<end>.";
246:         } else if ($args[1] == "cmd" && $type == "all") {
247:             $msg = "Updated status of command <highlight>$cmd<end> to <highlight>".$args[3]."d<end>.";
248:         } else if ($args[1] == "subcmd" && $type != "all") {
249:             $msg = "Updated status of subcommand <highlight>$cmd<end> to <highlight>".$args[3]."d<end> in channel <highlight>$type<end>.";
250:         } else if ($args[1] == "subcmd" && $type == "all") {
251:             $msg = "Updated status of subcommand <highlight>$cmd<end> to <highlight>".$args[3]."d<end>.";
252:         } else if ($args[1] == "event" && $file != "") {
253:             $msg = "Updated status of event <highlight>$event_type<end> to <highlight>".$args[3]."d<end>.";
254:         }
255:     
256:         $sendto->reply($msg);
257:     
258:         forEach ($data as $row) {
259:             // only update the status if the status is different
260:             if ($row->status != $status) {
261:                 if ($row->cmdevent == "event") {
262:                     if ($status == 1) {
263:                         $this->eventManager->activate($row->type, $row->file);
264:                     } else {
265:                         $this->eventManager->deactivate($row->type, $row->file);
266:                     }
267:                 } else if ($row->cmdevent == "cmd") {
268:                     if ($status == 1) {
269:                         $this->commandManager->activate($row->type, $row->file, $row->cmd, $row->admin);
270:                     } else {
271:                         $this->commandManager->deactivate($row->type, $row->file, $row->cmd, $row->admin);
272:                     }
273:                 }
274:             }
275:         }
276:     
277:         if ($args[1] == "mod" && $type == "all") {
278:             $this->db->exec("UPDATE cmdcfg_<myname> SET `status` = ? WHERE `module` = ?", $status, $module);
279:             $this->db->exec("UPDATE eventcfg_<myname> SET `status` = ? WHERE `module` = ? AND `type` <> 'setup'", $status, $module);
280:         } else if ($args[1] == "mod" && $type != "all") {
281:             $this->db->exec("UPDATE cmdcfg_<myname> SET `status` = ? WHERE `module` = ? AND `type` = ?", $status, $module, $type);
282:             $this->db->exec("UPDATE eventcfg_<myname> SET `status` = ? WHERE `module` = ? AND `type` = ? AND `type` <> 'setup'", $status, $module, $event_type);
283:         } else if ($args[1] == "cmd" && $type != "all") {
284:             $this->db->exec("UPDATE cmdcfg_<myname> SET `status` = ? WHERE `cmd` = ? AND `type` = ? AND `cmdevent` = 'cmd'", $status, $cmd, $type);
285:         } else if ($args[1] == "cmd" && $type == "all") {
286:             $this->db->exec("UPDATE cmdcfg_<myname> SET `status` = ? WHERE `cmd` = ? AND `cmdevent` = 'cmd'", $status, $cmd);
287:         } else if ($args[1] == "subcmd" && $type != "all") {
288:             $this->db->exec("UPDATE cmdcfg_<myname> SET `status` = ? WHERE `cmd` = ? AND `type` = ? AND `cmdevent` = 'subcmd'", $status, $cmd, $type);
289:         } else if ($args[1] == "subcmd" && $type == "all") {
290:             $this->db->exec("UPDATE cmdcfg_<myname> SET `status` = ? WHERE `cmd` = ? AND `cmdevent` = 'subcmd'", $status, $cmd);
291:         } else if ($args[1] == "event" && $file != "") {
292:             $this->db->exec("UPDATE eventcfg_<myname> SET `status` = ? WHERE `type` = ? AND `file` = ? AND `type` <> 'setup'", $status, $event_type, $file);
293:         }
294:     
295:         // for subcommands which are handled differently
296:         $this->subcommandManager->loadSubcommands();
297:     }
298: 
299:     /**
300:      * This command handler sets command's access level on a particular channel.
301:      * Note: This handler has not been not registered, only activated.
302:      *
303:      * @Matches("/^config (subcmd|cmd) (.+) admin (msg|priv|guild|all) (.+)$/i")
304:      */
305:     public function setAccessLevelOfChannelCommand($message, $channel, $sender, $sendto, $args) {
306:         $category = strtolower($args[1]);
307:         $command = strtolower($args[2]);
308:         $channel = strtolower($args[3]);
309:         $accessLevel = $this->accessManager->getAccessLevel($args[4]);
310:     
311:         if ($category == "cmd") {
312:             if ($channel == "all") {
313:                 $sql = "SELECT * FROM cmdcfg_<myname> WHERE `cmd` = '$command' AND `cmdevent` = 'cmd'";
314:             } else {
315:                 $sql = "SELECT * FROM cmdcfg_<myname> WHERE `cmd` = '$command' AND `type` = '$channel' AND `cmdevent` = 'cmd'";
316:             }
317:             $data = $this->db->query($sql);
318:     
319:             if (count($data) == 0) {
320:                 if ($channel == "all") {
321:                     $msg = "Could not find command <highlight>$command<end>.";
322:                 } else {
323:                     $msg = "Could not find command <highlight>$command<end> for channel <highlight>$channel<end>.";
324:                 }
325:             } else if (!$this->checkCommandAccessLevels($data, $sender)) {
326:                 $msg = "You do not have the required access level to change this command.";
327:             } else if (!$this->accessManager->checkAccess($sender, $accessLevel)) {
328:                 $msg = "You may not set the access level for a command above your own access level.";
329:             } else {
330:                 $this->commandManager->updateStatus($channel, $command, null, 1, $accessLevel);
331:         
332:                 if ($channel == "all") {
333:                     $msg = "Updated access of command <highlight>$command<end> to <highlight>$accessLevel<end>.";
334:                 } else {
335:                     $msg = "Updated access of command <highlight>$command<end> in channel <highlight>$channel<end> to <highlight>$accessLevel<end>.";
336:                 }
337:             }
338:         } else {  // if ($category == 'subcmd')
339:             $sql = "SELECT * FROM cmdcfg_<myname> WHERE `type` = ? AND `cmdevent` = 'subcmd' AND `cmd` = ?";
340:             $data = $this->db->query($sql, $channel, $command);
341:             if (count($data) == 0) {
342:                 $msg = "Could not find subcommand <highlight>$command<end> for channel <highlight>$channel<end>.";
343:             } else if (!$this->checkCommandAccessLevels($data, $sender)) {
344:                 $msg = "You do not have the required access level to change this subcommand.";
345:             } else if (!$this->accessManager->checkAccess($sender, $accessLevel)) {
346:                 $msg = "You may not set the access level for a subcommand above your own access level.";
347:             } else {
348:                 $this->db->exec("UPDATE cmdcfg_<myname> SET `admin` = ? WHERE `type` = ? AND `cmdevent` = 'subcmd' AND `cmd` = ?", $accessLevel, $channel, $command);
349:                 $this->subcommandManager->loadSubcommands();
350:                 $msg = "Updated access of subcommand <highlight>$command<end> in channel <highlight>$channel<end> to <highlight>$accessLevel<end>.";
351:             }
352:         }
353:         $sendto->reply($msg);
354:     }
355:     
356:     public function checkCommandAccessLevels($data, $sender) {
357:         forEach ($data as $row) {
358:             if (!$this->accessManager->checkAccess($sender, $row->admin)) {
359:                 return false;
360:             }
361:         }
362:         return true;
363:     }
364: 
365:     /**
366:      * This command handler shows information and controls of a command in
367:      * each channel.
368:      * Note: This handler has not been not registered, only activated.
369:      *
370:      * @Matches("/^config cmd ([a-z0-9_]+)$/i")
371:      */
372:     public function configCommandCommand($message, $channel, $sender, $sendto, $args) {
373:         $cmd = strtolower($args[1]);
374:         $found_msg = 0;
375:         $found_priv = 0;
376:         $found_guild = 0;
377:     
378:         $aliasCmd = $this->commandAlias->getBaseCommandForAlias($cmd);
379:         if ($aliasCmd != null) {
380:             $cmd = $aliasCmd;
381:         }
382:     
383:         $data = $this->db->query("SELECT * FROM cmdcfg_<myname> WHERE `cmd` = ?", $cmd);
384:         if (count($data) == 0) {
385:             $msg = "Could not find command <highlight>$cmd<end>.";
386:         } else {
387:             $blob = '';
388:     
389:             $blob .= "<header2>Tells:<end> ";
390:             $blob .= $this->getCommandInfo($cmd, 'msg');
391:             $blob .= "\n\n";
392: 
393:             $blob .= "<header2>Private Channel:<end> ";
394:             $blob .= $this->getCommandInfo($cmd, 'priv');
395:             $blob .= "\n\n";
396:             
397:             $blob .= "<header2>Guild Channel:<end> ";
398:             $blob .= $this->getCommandInfo($cmd, 'guild');
399:             $blob .= "\n\n";
400:     
401:             $subcmd_list = '';
402:             $output = $this->getSubCommandInfo($cmd, 'msg');
403:             if ($output) {
404:                 $subcmd_list .= "<header2>Available Subcommands in tells<end>\n";
405:                 $subcmd_list .= $output;
406:             }
407:     
408:             $output = $this->getSubCommandInfo($cmd, 'priv');
409:             if ($output) {
410:                 $subcmd_list .= "<header2>Available Subcommands in Private Channel<end>\n";
411:                 $subcmd_list .= $output;
412:             }
413:     
414:             $output = $this->getSubCommandInfo($cmd, 'guild');
415:             if ($output) {
416:                 $subcmd_list .= "<header2>Available Subcommands in Guild Channel<end>\n";
417:                 $subcmd_list .= $output;
418:             }
419:     
420:             if ($subcmd_list) {
421:                 $blob .= "<header>Subcommands<end>\n\n";
422:                 $blob .= $subcmd_list;
423:             }
424:     
425:             $help = $this->helpManager->find($cmd, $sender);
426:             if ($help) {
427:                 $blob .= "<header>Help ($cmd)<end>\n\n" . $help;
428:             }
429:     
430:             $msg = $this->text->makeBlob(ucfirst($cmd)." Config", $blob);
431:         }
432:         $sendto->reply($msg);
433:     }
434: 
435:     public function getAliasInfo($cmd) {
436:         $aliases = $this->commandAlias->findAliasesByCommand($cmd);
437:         $count = 0;
438:         forEach ($aliases as $row) {
439:             if ($row->status == 1) {
440:                 $count++;
441:                 $aliases_blob .= "{$row->alias}, ";
442:             }
443:         }
444: 
445:         $blob = '';
446:         if ($count > 0) {
447:             $blob .= "Aliases: <highlight>$aliases_blob<end>\n\n";
448:         }
449:         return $blob;
450:     }
451: 
452:     /**
453:      * This command handler shows configuration and controls for a single module.
454:      * Note: This handler has not been not registered, only activated.
455:      *
456:      * @Matches("/^config ([a-z0-9_]+)$/i")
457:      */
458:     public function configModuleCommand($message, $channel, $sender, $sendto, $args) {
459:         $module = strtoupper($args[1]);
460:         $found = false;
461:     
462:         $on = $this->text->makeChatcmd("Enable", "/tell <myname> config mod {$module} enable all");
463:         $off = $this->text->makeChatcmd("Disable", "/tell <myname> config mod {$module} disable all");
464:     
465:         $blob = "Enable/disable entire module: ($on/$off)\n";
466:     
467:         $data = $this->db->query("SELECT * FROM settings_<myname> WHERE `module` = ? ORDER BY mode, description", $module);
468:         if (count($data) > 0) {
469:             $found = true;
470:             $blob .= "\n<header2>Settings<end>\n";
471:         }
472:     
473:         forEach ($data as $row) {
474:             $blob .= $row->description;
475:     
476:             if ($row->mode == "edit") {
477:                 $blob .= " (" . $this->text->makeChatcmd("Modify", "/tell <myname> settings change $row->name") . ")";
478:             }
479:     
480:             $settingHandler = $this->settingManager->getSettingHandler($row);
481:             $blob .= ": " . $settingHandler->displayValue() . "\n";
482:         }
483:     
484:         $sql =
485:             "SELECT
486:                 *,
487:                 SUM(CASE WHEN type = 'guild' THEN 1 ELSE 0 END) guild_avail,
488:                 SUM(CASE WHEN type = 'guild' AND status = 1 THEN 1 ELSE 0 END) guild_status,
489:                 SUM(CASE WHEN type ='priv' THEN 1 ELSE 0 END) priv_avail,
490:                 SUM(CASE WHEN type = 'priv' AND status = 1 THEN 1 ELSE 0 END) priv_status,
491:                 SUM(CASE WHEN type ='msg' THEN 1 ELSE 0 END) msg_avail,
492:                 SUM(CASE WHEN type = 'msg' AND status = 1 THEN 1 ELSE 0 END) msg_status
493:             FROM
494:                 cmdcfg_<myname> c
495:             WHERE
496:                 (`cmdevent` = 'cmd' OR `cmdevent` = 'subcmd')
497:                 AND `module` = ?
498:             GROUP BY
499:                 cmd";
500:         $data = $this->db->query($sql, $module);
501:         if (count($data) > 0) {
502:             $found = true;
503:             $blob .= "\n<header2>Commands<end>\n";
504:         }
505:         forEach ($data as $row) {
506:             $guild = '';
507:             $priv = '';
508:             $msg = '';
509:     
510:             if ($row->cmdevent == 'cmd') {
511:                 $on = $this->text->makeChatcmd("ON", "/tell <myname> config cmd $row->cmd enable all");
512:                 $off = $this->text->makeChatcmd("OFF", "/tell <myname> config cmd $row->cmd disable all");
513:                 $cmdNameLink = $this->text->makeChatcmd($row->cmd, "/tell <myname> config cmd $row->cmd");
514:             } else if ($row->cmdevent == 'subcmd') {
515:                 $on = $this->text->makeChatcmd("ON", "/tell <myname> config subcmd $row->cmd enable all");
516:                 $off = $this->text->makeChatcmd("OFF", "/tell <myname> config subcmd $row->cmd disable all");
517:                 $cmdNameLink = $row->cmd;
518:             }
519:     
520:             if ($row->msg_avail == 0) {
521:                 $tell = "|_";
522:             } else if ($row->msg_status == 1) {
523:                 $tell = "<green>T<end>";
524:             } else {
525:                 $tell = "<red>T<end>";
526:             }
527:     
528:             if ($row->guild_avail == 0) {
529:                 $guild = "|_";
530:             } else if ($row->guild_status == 1) {
531:                 $guild = "|<green>G<end>";
532:             } else {
533:                 $guild = "|<red>G<end>";
534:             }
535:     
536:             if ($row->priv_avail == 0) {
537:                 $priv = "|_";
538:             } else if ($row->priv_status == 1) {
539:                 $priv = "|<green>P<end>";
540:             } else {
541:                 $priv = "|<red>P<end>";
542:             }
543:     
544:             if ($row->description != "") {
545:                 $blob .= "$cmdNameLink ($adv$tell$guild$priv): $on  $off - ($row->description)\n";
546:             } else {
547:                 $blob .= "$cmdNameLink - ($adv$tell$guild$priv): $on  $off\n";
548:             }
549:         }
550:     
551:         $data = $this->db->query("SELECT * FROM eventcfg_<myname> WHERE `type` <> 'setup' AND `module` = ?", $module);
552:         if (count($data) > 0) {
553:             $found = true;
554:             $blob .= "\n<header2>Events<end>\n";
555:         }
556:         forEach ($data as $row) {
557:             $on = $this->text->makeChatcmd("ON", "/tell <myname> config event ".$row->type." ".$row->file." enable all");
558:             $off = $this->text->makeChatcmd("OFF", "/tell <myname> config event ".$row->type." ".$row->file." disable all");
559:     
560:             if ($row->status == 1) {
561:                 $status = "<green>Enabled<end>";
562:             } else {
563:                 $status = "<red>Disabled<end>";
564:             }
565:     
566:             if ($row->description != "none") {
567:                 $blob .= "$row->type ($row->description) - ($status): $on  $off \n";
568:             } else {
569:                 $blob .= "$row->type - ($status): $on  $off \n";
570:             }
571:         }
572:     
573:         if ($found) {
574:             $msg = $this->text->makeBlob("$module Configuration", $blob);
575:         } else {
576:             $msg = "Could not find module <highlight>$module<end>.";
577:         }
578:         $sendto->reply($msg);
579:     }
580: 
581:     /**
582:      * This helper method converts given short access level name to long name.
583:      */
584:     private function getAdminDescription($admin) {
585:         $desc = $this->accessManager->getDisplayName($admin);
586:         return ucfirst(strtolower($desc));
587:     }
588: 
589:     /**
590:      * This helper method builds information and controls for given command.
591:      */
592:     private function getCommandInfo($cmd, $type) {
593:         $msg = "";
594:         $data = $this->db->query("SELECT * FROM cmdcfg_<myname> WHERE `cmd` = ? AND `type` = ?", $cmd, $type);
595:         if (count($data) == 0) {
596:             $msg .= "<red>Unused<end>\n";
597:         } else if (count($data) == 1) {
598:             $row = $data[0];
599: 
600:             $found_msg = 1;
601: 
602:             $row->admin = $this->getAdminDescription($row->admin);
603: 
604:             if ($row->status == 1) {
605:                 $status = "<green>Enabled<end>";
606:             } else {
607:                 $status = "<red>Disabled<end>";
608:             }
609: 
610:             $msg .= "$status (Access: $row->admin) \n";
611:             $msg .= "Set status: ";
612:             $msg .= $this->text->makeChatcmd("Enabled", "/tell <myname> config cmd {$cmd} enable {$type}") . "  ";
613:             $msg .= $this->text->makeChatcmd("Disabled", "/tell <myname> config cmd {$cmd} disable {$type}") . "\n";
614: 
615:             $msg .= "Set access level: ";
616:             forEach ($this->accessManager->getAccessLevels() as $accessLevel => $level) {
617:                 if ($accessLevel == 'none') {
618:                     continue;
619:                 }
620:                 $msg .= $this->text->makeChatcmd(ucfirst($accessLevel), "/tell <myname> config cmd {$cmd} admin {$type} $accessLevel") . "  ";
621:             }
622:             $msg .= "\n";
623:         } else {
624:             $this->logger->log("ERROR", "Multiple rows exists for cmd: '$cmd' and type: '$type'");
625:         }
626:         return $msg;
627:     }
628: 
629:     /**
630:      * This helper method builds information and controls for given subcommand.
631:      */
632:     private function getSubCommandInfo($cmd, $type) {
633:         $subcmd_list = '';
634:         $data = $this->db->query("SELECT * FROM cmdcfg_<myname> WHERE dependson = ? AND `type` = ? AND `cmdevent` = 'subcmd'", $cmd, $type);
635:         forEach ($data as $row) {
636:             $subcmd_list .= "Command: $row->cmd\n";
637:             if ($row->description != "") {
638:                 $subcmd_list .= "Description: $row->description\n";
639:             }
640: 
641:             $row->admin = $this->getAdminDescription($row->admin);
642: 
643:             if ($row->status == 1) {
644:                 $status = "<green>Enabled<end>";
645:             } else {
646:                 $status = "<red>Disabled<end>";
647:             }
648: 
649:             $subcmd_list .= "Current Status: $status (Access: $row->admin) \n";
650:             $subcmd_list .= "Set status: ";
651:             $subcmd_list .= $this->text->makeChatcmd("Enabled", "/tell <myname> config subcmd {$row->cmd} enable {$type}") . "  ";
652:             $subcmd_list .= $this->text->makeChatcmd("Disabled", "/tell <myname> config subcmd {$row->cmd} disable {$type}") . "\n";
653: 
654:             $subcmd_list .= "Set access level: ";
655:             forEach ($this->accessManager->getAccessLevels() as $accessLevel => $level) {
656:                 if ($accessLevel == 'none') {
657:                     continue;
658:                 }
659:                 $subcmd_list .= $this->text->makeChatcmd(ucfirst($accessLevel), "/tell <myname> config subcmd {$row->cmd} admin {$type} $accessLevel") . "  ";
660:             }
661:             $subcmd_list .= "\n\n";
662:         }
663:         return $subcmd_list;
664:     }
665: }
666: 
Budabot 4 Docs API documentation generated by ApiGen