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\User\Modules;
  4: 
  5: /**
  6:  * Authors: 
  7:  *  - Tyrence (RK2)
  8:  *
  9:  * @Instance
 10:  *
 11:  * Commands this controller contains:
 12:  *  @DefineCommand(
 13:  *      command     = 'random', 
 14:  *      accessLevel = 'all', 
 15:  *      description = 'Randomize a list of names/items', 
 16:  *      help        = 'random.txt'
 17:  *  )
 18:  *  @DefineCommand(
 19:  *      command     = 'roll', 
 20:  *      accessLevel = 'all', 
 21:  *      description = 'Roll a random number', 
 22:  *      help        = 'roll.txt'
 23:  *  )
 24:  *  @DefineCommand(
 25:  *      command     = 'verify', 
 26:  *      accessLevel = 'all', 
 27:  *      description = 'Verifies a roll', 
 28:  *      help        = 'roll.txt'
 29:  *  )
 30:  */
 31: class RandomController {
 32: 
 33:     /**
 34:      * Name of the module.
 35:      * Set automatically by module loader.
 36:      */
 37:     public $moduleName;
 38:     
 39:     /** @Inject */
 40:     public $db;
 41: 
 42:     /** @Inject */
 43:     public $text;
 44:     
 45:     /** @Inject */
 46:     public $util;
 47:     
 48:     /** @Inject */
 49:     public $settingManager;
 50:     
 51:     /** @Inject */
 52:     public $commandAlias;
 53:     
 54:     /**
 55:      * @Setting("time_between_rolls")
 56:      * @Description("How much time is required between rolls from the same person")
 57:      * @Visibility("edit")
 58:      * @Type("time")
 59:      * @Options("10s;30s;60s;90s")
 60:      */
 61:     public $defaultTimeBetweenRolls = "30s";
 62:     
 63:     /**
 64:      * This handler is called on bot startup.
 65:      * @Setup
 66:      */
 67:     public function setup() {
 68:         $this->db->loadSQLFile($this->moduleName, 'roll');
 69:         
 70:         $this->commandAlias->register($this->moduleName, "roll heads tails", "flip");
 71:     }
 72:     
 73:     /**
 74:      * @HandlesCommand("random")
 75:      * @Matches("/^random (.+)$/i")
 76:      */
 77:     public function randomCommand($message, $channel, $sender, $sendto, $args) {
 78:         $text = explode(" ", trim($args[1]));
 79:         $low = 0;
 80:         $high = count($text) - 1;
 81:         while (true) {
 82:             $random = rand($low, $high);
 83:             if (!isset($marked[$random])) {
 84:                 $count++;
 85:                 $list []= $text[$random];
 86:                 $marked[$random] = 1;
 87:                 if (count($marked) == count($text)) {
 88:                     break;
 89:                 }
 90:             }
 91:             $i = $low;
 92:             while (true) {
 93:                 if ($marked[$i] != 1) {
 94:                     $low = $i;
 95:                     break;
 96:                 } else {
 97:                     $i++;
 98:                 }
 99:             }
100:             $i = $high;
101:             while (true) {
102:                 if ($marked[$i] != 1) {
103:                     $high = $i;
104:                     break;
105:                 } else {
106:                     $i--;
107:                 }
108:             }
109:         }
110:         
111:         $sendto->reply(implode(" ", $list));
112:     }
113: 
114:     /**
115:      * @HandlesCommand("roll")
116:      * @Matches("/^roll ([0-9]+)$/i")
117:      * @Matches("/^roll ([0-9]+) ([0-9]+)$/i")
118:      */
119:     public function rollNumericCommand($message, $channel, $sender, $sendto, $args) {
120:         if (count($args) == 3) {
121:             $min = $args[1];
122:             $max = $args[2];
123:         } else {
124:             $min = 1;
125:             $max = $args[1];
126:         }
127:         
128:         if ($min >= $max) {
129:             $msg = "The first number cannot be higher than or equal to the second number.";
130:         } else {
131:             $timeBetweenRolls = $this->settingManager->get('time_between_rolls');
132:             $row = $this->db->queryRow("SELECT * FROM roll WHERE `name` = ? AND `time` >= ? LIMIT 1", $sender, time() - $timeBetweenRolls);
133:             if ($row === null) {
134:                 $options = array();
135:                 for ($i = $min; $i <= $max; $i++) {
136:                     $options []= $i;
137:                 }
138:                 list($ver_num, $result) = $this->roll($sender, $options);
139:                 $msg = "The roll is <highlight>$result<end> between $min and $max. To verify do /tell <myname> verify $ver_num";
140:             } else {
141:                 $msg = "You can only roll once every $timeBetweenRolls seconds.";
142:             }
143:         }
144: 
145:         $sendto->reply($msg);
146:     }
147:     
148:     /**
149:      * @HandlesCommand("roll")
150:      * @Matches("/^roll (.+)$/i")
151:      */
152:     public function rollNamesCommand($message, $channel, $sender, $sendto, $args) {
153:         $names = $args[1];
154:         $timeBetweenRolls = $this->settingManager->get('time_between_rolls');
155:         $row = $this->db->queryRow("SELECT * FROM roll WHERE `name` = ? AND `time` >= ? LIMIT 1", $sender, time() - $timeBetweenRolls);
156:         if ($row === null) {
157:             $options = explode(' ', $names);
158:             list($ver_num, $result) = $this->roll($sender, $options);
159:             $msg = "The roll is <highlight>$result<end> out of possible options: $names. To verify do /tell <myname> verify $ver_num";
160:         } else {
161:             $msg = "You can only roll once every $timeBetweenRolls seconds.";
162:         }
163: 
164:         $sendto->reply($msg);
165:     }
166:     
167:     /**
168:      * @HandlesCommand("verify")
169:      * @Matches("/^verify ([0-9]+)$/i")
170:      */
171:     public function verifyCommand($message, $channel, $sender, $sendto, $args) {
172:         $id = $args[1];
173:         $row = $this->db->queryRow("SELECT * FROM roll WHERE `id` = ?", $id);
174:         if ($row === null) {
175:             $msg = "Verify number <highlight>$id<end> does not exist.";
176:         } else {
177:             $time = $this->util->unixtimeToReadable(time() - $row->time);
178:             $msg = "<highlight>$row->result<end> rolled by <highlight>$row->name<end> $time ago. Possible options: ";
179:             $msg .= str_replace("|", " ", $row->options) . ".";
180:         }
181: 
182:         $sendto->reply($msg);
183:     }
184:     
185:     public function roll($sender, $options) {
186:         $result = $this->util->randomArrayValue($options);
187:         $this->db->exec("INSERT INTO roll (`time`, `name`, `options`, `result`) VALUES (?, ?, ?, ?)", time(), $sender, implode($options, "|"), $result);
188:         return array($this->db->lastInsertId(), $result);
189:     }
190: }
191: 
Budabot 4 Docs API documentation generated by ApiGen