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: /**
  6:  * @Instance
  7:  *
  8:  * Commands this controller contains:
  9:  *  @DefineCommand(
 10:  *      command       = 'cmdsearch',
 11:  *      alias         = 'searchcmd',
 12:  *      accessLevel   = 'all',
 13:  *      description   = 'Finds commands based on key words',
 14:  *      defaultStatus = 1,
 15:  *      help          = 'cmdsearch.txt'
 16:  *  )
 17:  */
 18: class CommandSearchController {
 19: 
 20:     /** @Inject */
 21:     public $chatBot;
 22: 
 23:     /** @Inject */
 24:     public $db;
 25: 
 26:     /** @Inject */
 27:     public $text;
 28: 
 29:     /** @Inject */
 30:     public $accessManager;
 31: 
 32:     private $searchWords;
 33: 
 34:     /**
 35:      * @HandlesCommand("cmdsearch")
 36:      * @Matches("/^cmdsearch (.*)/i")
 37:      */
 38:     public function searchCommand($message, $channel, $sender, $sendto, $arr) {
 39:         $this->searchWords = explode(" ", $arr[1]);
 40: 
 41:         // if a mod or higher, show all commands, not just enabled commands
 42:         $access = false;
 43:         if ($this->accessManager->checkAccess($sender, 'mod')) {
 44:             $access = true;
 45:         }
 46: 
 47:         $sqlquery = "SELECT DISTINCT module, cmd, help, description, admin FROM cmdcfg_<myname> WHERE cmd = ?";
 48:         if (!$access) {
 49:             $sqlquery .= " AND status = 1";
 50:         }
 51:         $results = $this->db->query($sqlquery, $arr[1]);
 52:         $results = $this->filterResultsByAccessLevel($sender, $results);
 53: 
 54:         $exactMatch = !empty($results);
 55: 
 56:         if (!$exactMatch) {
 57:             $results = $this->findSimilarCommands($this->searchWords, $access);
 58:             $results = $this->filterResultsByAccessLevel($sender, $results);
 59:             $results = array_slice($results, 0, 5);
 60:         }
 61: 
 62:         $msg = $this->render($results, $access, $exactMatch);
 63: 
 64:         $sendto->reply($msg);
 65: 
 66:         return true;
 67:     }
 68:     
 69:     public function filterResultsByAccessLevel($sender, $data) {
 70:         $results = array();
 71:         $charAccessLevel = $this->accessManager->getSingleAccessLevel($sender);
 72:         forEach ($data as $key => $row) {
 73:             if ($this->accessManager->compareAccessLevels($charAccessLevel, $row->admin) >= 0) {
 74:                 $results []= $row;
 75:             }
 76:         }
 77:         return $results;
 78:     }
 79:     
 80:     public function findSimilarCommands($wordArray, $includeDisabled = false) {
 81:         $sqlquery = "SELECT DISTINCT module, cmd, help, description, admin FROM cmdcfg_<myname>";
 82:         if (!$includeDisabled) {
 83:             $sqlquery .= " WHERE status = 1";
 84:         }
 85:         $data = $this->db->query($sqlquery);
 86: 
 87:         forEach ($data as $row) {
 88:             $keywords = explode(' ', $row->description);
 89:             array_push($keywords, $row->cmd);
 90:             $keywords = array_unique($keywords);
 91:             $row->distance = 0;
 92:             forEach ($wordArray as $searchWord) {
 93:                 $distance = 9999;
 94:                 forEach ($keywords as $keyword) {
 95:                     $distance = min($distance, levenshtein($keyword, $searchWord));
 96:                 }
 97:                 $row->distance += $distance;
 98:             }
 99:         }
100:         $results = $data;
101:         usort($results, array($this, 'sortByDistance'));
102:         
103:         return $results;
104:     }
105: 
106:     public function sortByDistance($row1, $row2) {
107:         $d1 = $row1->distance;
108:         $d2 = $row2->distance;
109:         if ($d1 == $d2) {
110:             return 0;
111:         }
112:         return ($d1 < $d2) ? -1 : 1;
113:     }
114: 
115:     public function render($results, $hasAccess, $exactMatch) {
116:         $blob = '';
117:         forEach ($results as $row) {
118:             if ($row->help != '') {
119:                 $helpLink = ' (' . $this->text->makeChatcmd("Help", "/tell <myname> help $row->cmd") . ')';
120:             }
121:             if ($hasAccess) {
122:                 $module = $this->text->makeChatcmd($row->module, "/tell <myname> config {$row->module}");
123:             } else {
124:                 $module = "{$row->module}";
125:             }
126: 
127:             $cmd = str_pad($row->cmd . " ", 20, ".");
128:             $blob .= "<highlight>{$cmd}<end> {$module} - {$row->description}{$helpLink}\n";
129:         }
130: 
131:         $count = count($results);
132:         if ($count == 0) {
133:             $msg = "No results found.";
134:         } else {
135:             if ($exactMatch) {
136:                 $msg = $this->text->makeBlob("Command Search Results ($count)", $blob);
137:             } else {
138:                 $msg = $this->text->makeBlob("Possible Matches ($count)", $blob);
139:             }
140:         }
141:         return $msg;
142:     }
143: }
144: 
Budabot 4 Docs API documentation generated by ApiGen