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       = 'ban',
 11:  *      accessLevel   = 'mod',
 12:  *      description   = 'Ban a character from this bot',
 13:  *      help          = 'ban.txt',
 14:  *      defaultStatus = '1'
 15:  *  )
 16:  *  @DefineCommand(
 17:  *      command       = 'banlist',
 18:  *      accessLevel   = 'mod',
 19:  *      description   = 'Shows who is on the banlist',
 20:  *      help          = 'ban.txt',
 21:  *      defaultStatus = '1'
 22:  *  )
 23:  *  @DefineCommand(
 24:  *      command       = 'unban',
 25:  *      accessLevel   = 'mod',
 26:  *      description   = 'Unban a character from this bot',
 27:  *      help          = 'ban.txt',
 28:  *      defaultStatus = '1'
 29:  *  )
 30:  */
 31: class BanController {
 32: 
 33:     /**
 34:      * Name of the module.
 35:      * Set automatically by module loader.
 36:      */
 37:     public $moduleName;
 38: 
 39:     /** @Inject */
 40:     public $accessManager;
 41: 
 42:     /** @Inject */
 43:     public $util;
 44: 
 45:     /** @Inject */
 46:     public $chatBot;
 47: 
 48:     /** @Inject */
 49:     public $settingManager;
 50: 
 51:     /** @Inject */
 52:     public $text;
 53: 
 54:     /** @Inject */
 55:     public $db;
 56: 
 57:     private $banlist = array();
 58: 
 59:     /**
 60:      * @Setting("notify_banned_player")
 61:      * @Description("Notify character when banned from bot")
 62:      * @Visibility("edit")
 63:      * @Type("options")
 64:      * @Options("true;false")
 65:      * @Intoptions("1;0")
 66:      * @AccessLevel("mod")
 67:      */
 68:     public $defaultNotifyBannedPlayer = "1";
 69: 
 70:     /**
 71:      * @Setup
 72:      * This handler is called on bot startup.
 73:      */
 74:     public function setup() {
 75:         $this->db->loadSQLFile($this->moduleName, "banlist");
 76:     }
 77: 
 78:     /**
 79:      * @Event("connect")
 80:      * @Description("Upload banlist into memory")
 81:      * @DefaultStatus("1")
 82:      */
 83:     public function initializeBanList($eventObj) {
 84:         $this->uploadBanlist();
 85:     }
 86: 
 87:     /**
 88:      * Command parameters are:
 89:      *  - name of the character
 90:      *  - time of ban
 91:      *  - banning reason string
 92:      *
 93:      * @HandlesCommand("ban")
 94:      * @Matches("/^ban ([a-z0-9-]+) ([a-z0-9]+) (for|reason) (.+)$/i")
 95:      */
 96:     public function banPlayerWithTimeAndReasonCommand($message, $channel, $sender, $sendto, $args) {
 97:         $who = ucfirst(strtolower($args[1]));
 98:         $length = $this->util->parseTime($args[2]);
 99:         $reason = $args[4];
100:     
101:         if (!$result = $this->banPlayer($who, $sender, $length, $reason, $sendto)) {
102:             return $result;
103:         }
104: 
105:         $timeString = $this->util->unixtimeToReadable($length);
106:         $sendto->reply("You have banned <highlight>$who<end> from this bot for $timeString.");
107:         if ($this->settingManager->get('notify_banned_player') == 1) {
108:             $this->chatBot->sendTell("You have been banned from this bot by <highlight>$sender<end> for $timeString. Reason: $reason", $who);
109:         }
110:     }
111: 
112:     /**
113:      * This command handler bans a player from this bot.
114:      *
115:      * Command parameters are:
116:      *  - name of the player
117:      *  - time of ban
118:      *
119:      * @HandlesCommand("ban")
120:      * @Matches("/^ban ([a-z0-9-]+) ([a-z0-9]+)$/i")
121:      */
122:     public function banPlayerWithTimeCommand($message, $channel, $sender, $sendto, $args) {
123:         $who = ucfirst(strtolower($args[1]));
124:         $length = $this->util->parseTime($args[2]);
125:     
126:         if (!$result = $this->banPlayer($who, $sender, $length, '', $sendto)) {
127:             return $result;
128:         }
129:     
130:         $timeString = $this->util->unixtimeToReadable($length);
131:         $sendto->reply("You have banned <highlight>$who<end> from this bot for $timeString.");
132:         if ($this->settingManager->get('notify_banned_player') == 1) {
133:             $this->chatBot->sendTell("You have been banned from this bot by <highlight>$sender<end> for $timeString.", $who);
134:         }
135:     }
136: 
137:     /**
138:      * This command handler bans a player from this bot.
139:      *
140:      * Command parameters are:
141:      *  - name of the player
142:      *  - banning reason string
143:      *
144:      * @HandlesCommand("ban")
145:      * @Matches("/^ban ([a-z0-9-]+) (for|reason) (.+)$/i")
146:      */
147:     public function banPlayerWithReasonCommand($message, $channel, $sender, $sendto, $args) {
148:         $who = ucfirst(strtolower($args[1]));
149:         $reason = $args[3];
150:     
151:         if (!$result = $this->banPlayer($who, $sender, null, $reason, $sendto)) {
152:             return $result;
153:         }
154:     
155:         $sendto->reply("You have permanently banned <highlight>$who<end> from this bot.");
156:         if ($this->settingManager->get('notify_banned_player') == 1) {
157:             $this->chatBot->sendTell("You have been permanently banned from this bot by <highlight>$sender<end>. Reason: $reason", $who);
158:         }
159:     }
160: 
161:     /**
162:      * This command handler bans a player from this bot.
163:      *
164:      * Command parameter is:
165:      *  - name of the player
166:      *
167:      * @HandlesCommand("ban")
168:      * @Matches("/^ban ([a-z0-9-]+)$/i")
169:      */
170:     public function banPlayerCommand($message, $channel, $sender, $sendto, $args) {
171:         $who = ucfirst(strtolower($args[1]));
172: 
173:         if (!$result = $this->banPlayer($who, $sender, null, '', $sendto)) {
174:             return $result;
175:         }
176:     
177:         $sendto->reply("You have permanently banned <highlight>$who<end> from this bot.");
178:         if ($this->settingManager->get('notify_banned_player') == 1) {
179:             $this->chatBot->sendTell("You have been permanently banned from this bot by <highlight>$sender<end>.", $who);
180:         }
181:     }
182: 
183:     /**
184:      * This command handler shows who is on the banlist.
185:      *
186:      * @HandlesCommand("banlist")
187:      * @Matches("/^banlist$/i")
188:      */
189:     public function banlistCommand($message, $channel, $sender, $sendto, $args) {
190:         $banlist = $this->getBanlist();
191:         $count = count($banlist);
192: 
193:         if ($count == 0) {
194:             $msg = "No one is currently banned from this bot.";
195:         } else {
196:             $blob = '';
197:             forEach ($banlist as $ban) {
198:                 $blob .= "Name: <highlight>{$ban->name}<end>\n";
199:                 $blob .= "<tab>Date: <highlight>" . $this->util->date($ban->time) . "<end>\n";
200:                 $blob .= "<tab>By: <highlight>{$ban->admin}<end>\n";
201:                 if ($ban->banend != 0) {
202:                     $blob .= "<tab>Ban ends: <highlight>" . $this->util->unixtimeToReadable($ban->banend - time(), false) . "<end>\n";
203:                 } else {
204:                     $blob .= "<tab>Ban ends: <highlight>Never<end>\n";
205:                 }
206:         
207:                 if ($ban->reason != '') {
208:                     $blob .= "<tab>Reason: <highlight>{$ban->reason}<end>\n";
209:                 }
210:                 $blob .= "\n";
211:             }
212:             $msg = $this->text->makeBlob("Banlist ($count)", $blob);
213:         }
214:         $sendto->reply($msg);
215:     }
216: 
217:     /**
218:      * This command handler unbans a player from this bot.
219:      *
220:      * Command parameter is:
221:      *  - name of the player
222:      *
223:      * @HandlesCommand("unban")
224:      * @Matches("/^unban (.+)$/i")
225:      */
226:     public function unbanCommand($message, $channel, $sender, $sendto, $args) {
227:         $who = ucfirst(strtolower($args[1]));
228: 
229:         $charId = $this->chatBot->get_uid($who);
230:         if (!$this->isBanned($charId)) {
231:             $sendto->reply("<highlight>$who<end> is not banned on this bot.");
232:             return;
233:         }
234:     
235:         $this->remove($charId);
236:     
237:         $sendto->reply("You have unbanned <highlight>$who<end> from this bot.");
238:         if ($this->settingManager->get('notify_banned_player') == 1) {
239:             $this->chatBot->sendTell("You have been unbanned from this bot by $sender.", $who);
240:         }
241:     }
242: 
243:     /**
244:      * @Event("timer(1min)")
245:      * @Description("Check temp bans to see if they have expired")
246:      * @DefaultStatus("1")
247:      */
248:     public function checkTempBan($eventObj) {
249:         $numRows = $this->db->exec("DELETE FROM banlist_<myname> WHERE banend != 0 AND banend < ?", time());
250: 
251:         if ($numRows > 0) {
252:             $this->uploadBanlist();
253:         }
254:     }
255: 
256:     /**
257:      * This helper method bans player with given arguments.
258:      */
259:     private function banPlayer($who, $sender, $length, $reason, $sendto) {
260:         $charId = $this->chatBot->get_uid($who);
261:         if ($charId == null) {
262:             $sendto->reply("Character <highlight>$who<end> does not exist.");
263:             return;
264:         }
265: 
266:         if ($this->isBanned($charId)) {
267:             $sendto->reply("Character <highlight>$who<end> is already banned.");
268:             return;
269:         }
270:     
271:         if ($this->accessManager->compareCharacterAccessLevels($sender, $who) <= 0) {
272:             $sendto->reply("You must have an access level higher than <highlight>$who<end> to perform this action.");
273:             return;
274:         }
275: 
276:         if ($length === 0) {
277:             return false;
278:         }
279: 
280:         $this->add($charId, $sender, $length, $reason);
281:         return true;
282:     }
283: 
284:     public function add($charId, $sender, $length, $reason) {
285: 
286:         if ($length == null) {
287:             $ban_end = "0";
288:         } else {
289:             $ban_end = time() + $length;
290:         }
291: 
292:         $sql = "INSERT INTO banlist_<myname> (`charid`, `admin`, `time`, `reason`, `banend`) VALUES (?, ?, ?, ?, ?)";
293:         $numrows = $this->db->exec($sql, $charId, $sender, time(), $reason, $ban_end);
294: 
295:         $this->uploadBanlist();
296: 
297:         return $numrows;
298:     }
299: 
300:     public function remove($charId) {
301:         $sql = "DELETE FROM banlist_<myname> WHERE charid = ?";
302:         $numrows = $this->db->exec($sql, $charId);
303: 
304:         $this->uploadBanlist();
305: 
306:         return $numrows;
307:     }
308: 
309:     public function uploadBanlist() {
310:         $this->banlist = array();
311: 
312:         $sql = "
313:             SELECT b.*, IFNULL(p.name, b.charid) AS name
314:             FROM banlist_<myname> b LEFT JOIN players p ON b.charid = p.charid";
315:         $data = $this->db->query($sql);
316:         forEach ($data as $row) {
317:             $this->banlist[$row->charid] = $row;
318:         }
319:     }
320: 
321:     public function isBanned($charId) {
322:         return isset($this->banlist[$charId]);
323:     }
324: 
325:     public function getBanlist() {
326:         return $this->banlist;
327:     }
328: }
329: 
Budabot 4 Docs API documentation generated by ApiGen