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 Budabot\Core\CommandReply;
  6: use Exception;
  7: 
  8: /**
  9:  * Authors: 
 10:  *  - Tyrence (RK2)
 11:  *
 12:  * @Instance
 13:  *
 14:  * Commands this controller contains:
 15:  *  @DefineCommand(
 16:  *      command     = 'profile', 
 17:  *      accessLevel = 'admin', 
 18:  *      description = 'View, add, remove, and load profiles', 
 19:  *      help        = 'profile.txt',
 20:  *      alias       = 'profiles'
 21:  *  )
 22:  */
 23: class ProfileController {
 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 $settingManager;
 36:     
 37:     /** @Inject */
 38:     public $text;
 39:     
 40:     /** @Inject */
 41:     public $util;
 42:     
 43:     /** @Inject */
 44:     public $commandManager;
 45:     
 46:     private $path;
 47:     private $fileExt = ".txt";
 48:     
 49:     /**
 50:      * This handler is called on bot startup.
 51:      * @Setup
 52:      */
 53:     public function setup() {
 54:         $this->path = getcwd() . "/data/profiles/";
 55:         
 56:         // make sure that the profile folder exists
 57:         if (!dir($this->path)) {
 58:             mkdir($this->path, 0777);
 59:         }
 60:     }
 61:     
 62:     /**
 63:      * @HandlesCommand("profile")
 64:      * @Matches("/^profile$/i")
 65:      */
 66:     public function profileListCommand($message, $channel, $sender, $sendto, $args) {
 67:         if ($handle = opendir($this->path)) {
 68:             $profileList = array();
 69: 
 70:             /* This is the correct way to loop over the directory. */
 71:             while (false !== ($fileName = readdir($handle))) {
 72:                 // if file has the correct extension, it's a profile file
 73:                 if ($this->util->endsWith($fileName, $this->fileExt)) {
 74:                     $profileList[] =  str_replace($this->fileExt, '', $fileName);
 75:                 }
 76:             }
 77: 
 78:             closedir($handle);
 79: 
 80:             sort($profileList);
 81: 
 82:             $linkContents = '';
 83:             forEach ($profileList as $profile) {
 84:                 $name = ucfirst(strtolower($profile));
 85:                 $viewLink = $this->text->makeChatcmd("View", "/tell <myname> profile view $profile");
 86:                 $loadLink = $this->text->makeChatcmd("Load", "/tell <myname> profile load $profile");
 87:                 $linkContents .= "$profile [$viewLink] [$loadLink]\n";
 88:             }
 89: 
 90:             if ($linkContents) {
 91:                 $linkContents .= "\n\n<orange>Warning: Running a profile script will change your configuration.  Proceed only if you understand the consequences.<end>";
 92:                 $msg = $this->text->makeBlob('Profiles (' . count($profileList) . ')', $linkContents);
 93:             } else {
 94:                 $msg = "No profiles available.";
 95:             }
 96:         } else {
 97:             $msg = "Could not open profiles directory.";
 98:         }
 99:         $sendto->reply($msg);
100:     }
101:     
102:     /**
103:      * @HandlesCommand("profile")
104:      * @Matches("/^profile view ([a-z0-9_-]+)$/i")
105:      */
106:     public function profileViewCommand($message, $channel, $sender, $sendto, $args) {
107:         $profileName = $args[1];
108:         $filename = $this->path . '/' . $profileName . $this->fileExt;
109:         if (!file_exists($filename)) {
110:             $msg = "Profile <highlight>$profileName<end> does not exist.";
111:         } else {
112:             $blob = htmlspecialchars(file_get_contents($filename));
113:             $msg = $this->text->makeBlob("Profile $profileName", $blob);
114:         }
115:         $sendto->reply($msg);
116:     }
117:     
118:     /**
119:      * @HandlesCommand("profile")
120:      * @Matches("/^profile save ([a-z0-9_-]+)$/i")
121:      */
122:     public function profileSaveCommand($message, $channel, $sender, $sendto, $args) {
123:         $profileName = $args[1];
124:         $filename = $this->path . '/' . $profileName . $this->fileExt;
125:         if (file_exists($filename)) {
126:             $msg = "Profile <highlight>$profileName<end> already exists.";
127:         } else {
128:             $contents = "# Settings\n";
129:             forEach ($this->settingManager->settings as $name => $value) {
130:                 if ($name != "botid" && $name != "version" && !$this->util->endsWith($name, "_db_version")) {
131:                     $contents .= "!settings save $name $value\n";
132:                 }
133:             }
134:             $contents .= "\n# Events\n";
135:             $data = $this->db->query("SELECT * FROM eventcfg_<myname>");
136:             forEach ($data as $row) {
137:                 $status = "disable";
138:                 if ($row->status == 1) {
139:                     $status = "enable";
140:                 }
141:                 $contents .= "!config event {$row->type} {$row->file} {$status} all\n";
142:             }
143:             $contents .= "\n# Commands\n";
144:             $data = $this->db->query("SELECT * FROM cmdcfg_<myname>");
145:             forEach ($data as $row) {
146:                 $status = "disable";
147:                 if ($row->status == 1) {
148:                     $status = "enable";
149:                 }
150:                 $contents .= "!config cmd {$row->cmd} {$status} {$row->type}\n";
151:             }
152:             $contents .= "\n# Aliases\n";
153:             $data = $this->db->query("SELECT * FROM cmd_alias_<myname> WHERE `status` = '1' ORDER BY alias ASC");
154:             forEach ($data as $row) {
155:                 $contents .= "!alias rem {$row->alias}\n";
156:                 $contents .= "!alias add {$row->alias} {$row->cmd}\n";
157:             }
158:             file_put_contents($filename, $contents);
159:             $msg = "Profile <highlight>$profileName<end> has been saved.";
160:         }
161:         $sendto->reply($msg);
162:     }
163:     
164:     /**
165:      * @HandlesCommand("profile")
166:      * @Matches("/^profile (rem|remove|del|delete) ([a-z0-9_-]+)$/i")
167:      */
168:     public function profileRemCommand($message, $channel, $sender, $sendto, $args) {
169:         $profileName = $args[2];
170:         $filename = $this->path . '/' . $profileName . $this->fileExt;
171:         if (!file_exists($filename)) {
172:             $msg = "Profile <highlight>$profileName<end> does not exist.";
173:         } else {
174:             unlink($filename);
175:             $msg = "Profile <highlight>$profileName<end> has been deleted.";
176:         }
177:         $sendto->reply($msg);
178:     }
179:     
180:     /**
181:      * @HandlesCommand("profile")
182:      * @Matches("/^profile load ([a-z0-9_-]+)$/i")
183:      */
184:     public function profileLoadCommand($message, $channel, $sender, $sendto, $args) {
185:         $profileName = $args[1];
186:         $filename = $this->getFilename($profileName);
187:         
188:         if (!file_exists($filename)) {
189:             $msg = "Profile <highlight>$profileName<end> does not exist.";
190:         } else {
191:             $sendto->reply("Loading profile <highlight>$profileName<end>...");
192:             $output = $this->loadProfile($filename, $sender);
193:             if ($ouptput === false) {
194:                 $msg = "There was an error loading the profile <highlight>$profileName<end>.";
195:             } else {
196:                 $msg = $this->text->makeBlob("Profile Results: $profileName", $output);
197:             }
198:         }
199:         $sendto->reply($msg);
200:     }
201:     
202:     public function getFilename($profileName) {
203:         return $this->path . '/' . $profileName . $this->fileExt;
204:     }
205:     
206:     public function loadProfile($filename, $sender) {
207:         $info = file_get_contents($filename);
208:         $lines = explode("\n", $info);
209:         $this->db->beginTransaction();
210:         try {
211:             $profileSendTo = new ProfileCommandReply();
212:             forEach ($lines as $line) {
213:                 if ($line[0] == "!") {
214:                     $profileSendTo->reply("<pagebreak>" . $line);
215:                     $line = substr(trim($line), 1);
216:                     $this->commandManager->process("msg", $line, $sender, $profileSendTo);
217:                     $profileSendTo->reply("\n");
218:                 }
219:             }
220:             $this->db->commit();
221:             return $profileSendTo->result;
222:         } catch (Exception $e) {
223:             $this->logger->log("ERROR", "Could not load profile", $e);
224:             $this->db->rollback();
225:             return false;
226:         }
227:     }
228: }
229: 
230: class ProfileCommandReply implements CommandReply {
231:     public $result;
232: 
233:     public function reply($msg) {
234:         $this->result .= $msg . "\n";
235:     }
236: }
237: 
Budabot 4 Docs API documentation generated by ApiGen