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: use stdClass;
  6: 
  7: /**
  8:  * @Instance
  9:  */
 10: class SettingManager {
 11:     /** @Inject */
 12:     public $db;
 13: 
 14:     /** @Inject */
 15:     public $chatBot;
 16: 
 17:     /** @Inject */
 18:     public $util;
 19: 
 20:     /** @Inject */
 21:     public $helpManager;
 22:     
 23:     /** @Inject */
 24:     public $accessManager;
 25: 
 26:     /** @Logger */
 27:     public $logger;
 28: 
 29:     public $settings = array();
 30: 
 31:     private $changeListeners = array();
 32: 
 33:     /**
 34:      * @name: add
 35:      * @param: $module - the module name
 36:      * @param: $name - the name of the setting
 37:      * @param: $description - a description for the setting (will appear in the config)
 38:      * @param: $mode - 'edit', 'noedit'
 39:      * @param: $type - 'color', 'number', 'text', 'options', or 'time'
 40:      * @param: $options - a list of values that the setting can be, semi-colon delimited (optional)
 41:      * @param: $intoptions - int values corresponding to $options; if empty, the values from $options will be what is stored in the database (optional)
 42:      * @param: $admin - the permission level needed to change this setting (default: mod) (optional)
 43:      * @param: $help - a help file for this setting; if blank, will use a help topic with the same name as this setting if it exists (optional)
 44:      * @description: Adds a new setting
 45:      */
 46:     public function add($module, $name, $description, $mode, $type, $value, $options = '', $intoptions = '', $accessLevel = 'mod', $help = '') {
 47:         $name = strtolower($name);
 48:         $type = strtolower($type);
 49: 
 50:         if ($accessLevel == '') {
 51:             $accessLevel = 'mod';
 52:         }
 53:         $accessLevel = $this->accessManager->getAccessLevel($accessLevel);
 54: 
 55:         if (!in_array($type, array('color', 'number', 'text', 'options', 'time'))) {
 56:             $this->logger->log('ERROR', "Error in registering Setting $module:setting($name). Type should be one of: 'color', 'number', 'text', 'options', 'time'. Actual: '$type'.");
 57:         }
 58: 
 59:         if ($type == 'time') {
 60:             $oldvalue = $value;
 61:             $value = $this->util->parseTime($value);
 62:             if ($value < 1) {
 63:                 $this->logger->log('ERROR', "Error in registering Setting $module:setting($name). Invalid time: '{$oldvalue}'.");
 64:                 return;
 65:             }
 66:         }
 67: 
 68:         if (!empty($help)) {
 69:             $help = $this->helpManager->checkForHelpFile($module, $help);
 70:         }
 71: 
 72:         try {
 73:             if (array_key_exists($name, $this->chatBot->existing_settings) || array_key_exists($name, $this->settings)) {
 74:                 $sql = "UPDATE settings_<myname> SET `module` = ?, `type` = ?, `mode` = ?, `options` = ?, `intoptions` = ?, `description` = ?, `admin` = ?, `verify` = 1, `help` = ? WHERE `name` = ?";
 75:                 $this->db->exec($sql, $module, $type, $mode, $options, $intoptions, $description, $accessLevel, $help, $name);
 76:             } else {
 77:                 $sql = "INSERT INTO settings_<myname> (`name`, `module`, `type`, `mode`, `value`, `options`, `intoptions`, `description`, `source`, `admin`, `verify`, `help`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
 78:                 $this->db->exec($sql, $name, $module, $type, $mode, $value, $options, $intoptions, $description, 'db', $accessLevel, '1', $help);
 79:                 $this->settings[$name] = $value;
 80:             }
 81:         } catch (SQLException $e) {
 82:             $this->logger->log('ERROR', "Error in registering Setting $module:setting($name): " . $e->getMessage());
 83:         }
 84:     }
 85:     
 86:     /**
 87:      * @name: exists
 88:      * @description: Determine if a setting with a given name exists
 89:      * @return: true if the setting exists, false otherwise
 90:      */
 91:     public function exists($name) {
 92:         return array_key_exists($name, $this->settings);
 93:     }
 94: 
 95:     /**
 96:      * @name: get
 97:      * @description: Gets the value of a setting
 98:      * @return: the value of the setting, or false if a setting with that name does not exist
 99:      */
100:     public function get($name) {
101:         $name = strtolower($name);
102:         if (array_key_exists($name, $this->settings)) {
103:             return $this->settings[$name];
104:         } else {
105:             $this->logger->log("ERROR", "Could not retrieve value for setting '$name' because setting does not exist");
106:             return false;
107:         }
108:     }
109: 
110:     /**
111:      * @name: save
112:      * @description: Saves a new value for a setting
113:      * @param: $name - the name of the setting
114:      * @param: @value - the new value to set the setting to
115:      * @return: false if the setting with that name does not exist, true otherwise
116:      */
117:     public function save($name, $value) {
118:         $name = strtolower($name);
119: 
120:         if (array_key_exists($name, $this->settings)) {
121:             if ($this->settings[$name] !== $value) {
122:                 // notify any listeners
123:                 if (isset($this->changeListeners[$name])) {
124:                     forEach ($this->changeListeners[$name] as $listener) {
125:                         call_user_func($listener->callback, $name, $this->settings[$name], $value, $listener->data);
126:                     }
127:                 }
128:                 $this->settings[$name] = $value;
129:                 $this->db->exec("UPDATE settings_<myname> SET `verify` = 1, `value` = ? WHERE `name` = ?", $value, $name);
130:             }
131:             return true;
132:         } else {
133:             $this->logger->log("ERROR", "Could not save value '$value' for setting '$name' because setting does not exist");
134:             return false;
135:         }
136:     }
137: 
138:     public function upload() {
139:         $this->settings = array();
140: 
141:         //Upload Settings from the db that are set by modules
142:         $data = $this->db->query("SELECT * FROM settings_<myname>");
143:         forEach ($data as $row) {
144:             $this->settings[$row->name] = $row->value;
145:         }
146:     }
147: 
148:     /**
149:      * Adds listener callback which will be called if given $settingName changes.
150:      *
151:      * The callback has following signature:
152:      * <code>function callback($value, $data)</code>
153:      * $value: new value of the setting
154:      * $data:  optional data variable given on register
155:      *
156:      * Example usage:
157:      * <code>
158:      *  registerChangeListener("some_setting_name", function($settingName, $oldValue, $newValue, $data) {
159:      *      // ...
160:      *  } );
161:      * </code>
162:      *
163:      * @param string   $settingName changed setting's name 
164:      * @param callback $callback    the callback function to call
165:      * $param mixed    $data        any data which will be passed to to the callback (optional)
166:      *
167:      * In the event of an invalid setting value, throw an exception with a message indicating why the value is invalid.
168:      */
169:     public function registerChangeListener($settingName, $callback, $data = null) {
170:         if (!is_callable($callback)) {
171:             $this->logger->log('ERROR', 'Given callback is not valid.');
172:             return;
173:         }
174:         $settingName = strtolower($settingName);
175: 
176:         $listener = new StdClass();
177:         $listener->callback = $callback;
178:         $listener->data = $data;
179:         $this->changeListeners[$settingName] []= $listener;
180:     }
181:     
182:     public function getSettingHandler($row) {
183:         $handler = null;
184:         switch ($row->type) {
185:             case 'color':
186:                 $handler = new ColorSettingHandler($row);
187:                 break;
188:             case 'text':
189:                 $handler = new TextSettingHandler($row);
190:                 break;
191:             case 'number':
192:                 $handler = new NumberSettingHandler($row);
193:                 break;
194:             case 'options':
195:                 $handler = new OptionsSettingHandler($row);
196:                 break;
197:             case 'time':
198:                 $handler = new TimeSettingHandler($row);
199:                 break;
200:             default:
201:                 $this->loggger->log('ERROR', "Could not find setting handler for setting type: '$row->type'");
202:         }
203:         Registry::injectDependencies($handler);
204:         return $handler;
205:     }
206: }
207: 
Budabot 4 Docs API documentation generated by ApiGen