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:  *  - Mindrila (RK1)
  8:  *  - Tyrence (RK2)
  9:  *
 10:  * @Instance
 11:  *
 12:  * Commands this class contains:
 13:  *  @DefineCommand(
 14:  *      command     = 'raffle',
 15:  *      accessLevel = 'all',
 16:  *      description = 'Raffle off items to players',
 17:  *      help        = 'raffle.txt'
 18:  *  )
 19:  */
 20: class RaffleController {
 21: 
 22:     /**
 23:      * Name of the module.
 24:      * Set automatically by module loader.
 25:      */
 26:     public $moduleName;
 27:     
 28:     /** @Inject */
 29:     public $settingManager;
 30:     
 31:     /** @Inject */
 32:     public $accessManager;
 33: 
 34:     /** @Inject */
 35:     public $text;
 36: 
 37:     /** @Inject */
 38:     public $util;
 39:     
 40:     /**
 41:      * @Setup
 42:      */
 43:     public function setup() {
 44:         if (!isset($this->raffles)) {
 45:             $this->raffles = array(
 46:                 "running" => false,
 47:                 "owner" => null,
 48:                 "item" => null,
 49:                 "count" => null,
 50:                 "time" => null,
 51:                 "rafflees" => null,
 52:                 "lastresult" => null,
 53:                 "nextmsgtime" => null,
 54:                 "sendto" => null
 55:             );
 56:         }
 57:     
 58:         $this->settingManager->add($this->moduleName, "defaultraffletime", "How long the raffle should go for", "edit", "time", '3m', '1m;2m;3m;4m;5m', '', 'mod', "raffle.txt");
 59:     }
 60:     
 61:     /**
 62:      * @HandlesCommand("raffle")
 63:      * @Matches("/^raffle start (\d+) (.+)$/i")
 64:      * @Matches("/^raffle start (.+)$/i")
 65:      */
 66:     public function raffleStartCommand($message, $channel, $sender, $sendto, $args) {
 67:         if ("msg" == $channel) {
 68:             $msg = "You cannot start a raffle in tells.  Use the org channel or private channel.";
 69:             $sendto->reply($msg);
 70:             return;
 71:         }
 72: 
 73:         if ($this->raffles["running"]) {
 74:             $msg = "There is already a raffle in progress.";
 75:             $sendto->reply($msg);
 76:             return;
 77:         }
 78: 
 79:         if (count($args) == 3) {
 80:             $item = $args[2];
 81:             $count = $args[1];
 82:         } else {
 83:             $item = $args[1];
 84:             $count = 1;
 85:         }
 86:         $seconds = $this->settingManager->get("defaultraffletime");
 87:         $timeString = $this->util->unixtimeToReadable($seconds);
 88: 
 89:         $this->raffles = array(
 90:             "running" => true,
 91:             "owner" => $sender,
 92:             "item" => $item,
 93:             "count" => $count,
 94:             "time" => time() +  $seconds,
 95:             "rafflees" => array(),
 96:             "lastresult" => null,
 97:             "sendto" => $sendto
 98:         );
 99:         
100:         $joinLink = $this->text->makeChatcmd("here", "/tell <myname> raffle join");
101:         $leaveLink = $this->text->makeChatcmd("here", "/tell <myname> raffle leave");
102: 
103:         $jnRflMsg = "<white>A raffle for $item (count: $count) has been started by $sender!<end>
104: 
105:     Click $joinLink to join the raffle!
106:     Click $leaveLink if you wish to leave the raffle.";
107:         $link = $this->text->makeBlob("here", $jnRflMsg, 'Raffle');
108:         $msg = "
109:     -----------------------------------------------------------------------
110:     A raffle for $item (count: $count) has been started by $sender!
111:     Click $link to join the raffle. Raffle will end in $timeString.
112:     -----------------------------------------------------------------------";
113: 
114:         $this->raffles["nextmsgtime"] = $this->getNextTime($this->raffles["time"]);
115:         $sendto->reply($msg);
116:     }
117: 
118:     /**
119:      * @HandlesCommand("raffle")
120:      * @Matches("/^raffle cancel$/i")
121:      */
122:     public function raffleCancelCommand($message, $channel, $sender, $sendto, $args) {
123:         if (!$this->raffles["running"]) {
124:             $msg = "There is no active raffle.";
125:             $sendto->reply($msg);
126:             return;
127:         }
128: 
129:         if (($this->raffles["owner"] != $sender) && !$this->accessManager->checkAccess($sender, "mod")) {
130:             $msg = "Only the owner or a moderator may cancel the raffle.";
131:             $sendto->reply($msg);
132:             return;
133:         }
134:         $sendtobuffer = $this->raffles["sendto"];
135:         $this->raffles = array(
136:             "running" => false,
137:             "owner" => null,
138:             "item" => null,
139:             "count" => null,
140:             "time" => null,
141:             "rafflees" => null,
142:             "lastresult" => "The last raffle was cancelled.",
143:             "sendto" => $sendtobuffer
144:         );
145: 
146:         $msg = "The raffle was cancelled.";
147:         $this->raffles["sendto"]->reply($msg);
148:     }
149:     
150:     /**
151:      * @HandlesCommand("raffle")
152:      * @Matches("/^raffle end$/i")
153:      */
154:     public function raffleEndCommand($message, $channel, $sender, $sendto, $args) {
155:         if (!$this->raffles["running"]) {
156:             $msg = "There is no active raffle.";
157:             $sendto->reply($msg);
158:             return;
159:         }
160: 
161:         if (($this->raffles["owner"] != $sender) && !$this->accessManager->checkAccess($sender, "mod")) {
162:             $msg = "Only the owner or a moderator may end the raffle.";
163:             $sendto->reply($msg);
164:             return;
165:         }
166: 
167:         $this->endraffle();
168:     }
169:     
170:     /**
171:      * @HandlesCommand("raffle")
172:      * @Matches("/^raffle result$/i")
173:      */
174:     public function raffleResultCommand($message, $channel, $sender, $sendto, $args) {
175:         if (!isset ($this->raffles["lastresult"])) {
176:             $msg = "Last raffles result could not be retrieved.";
177:             $sendto->reply($msg);
178:             return;
179:         }
180: 
181:         $sendto->reply("Last raffle result: ".$this->raffles["lastresult"]);
182:     }
183:     
184:     /**
185:      * @HandlesCommand("raffle")
186:      * @Matches("/^raffle join$/i")
187:      */
188:     public function raffleJoinCommand($message, $channel, $sender, $sendto, $args) {
189:         if (!$this->raffles["running"]) {
190:             $msg = "There is no active raffle.";
191:             $sendto->reply($msg);
192:             return;
193:         }
194: 
195:         if (isset($this->raffles["rafflees"][$sender])) {
196:             $msg = "You are already in the raffle.";
197:             $sendto->reply($msg);
198:             return;
199:         }
200: 
201:         $this->raffles["rafflees"][$sender] = 0;
202:         $msg = "$sender has entered the raffle.";
203:         $this->raffles["sendto"]->reply($msg);
204:     }
205:     
206:     /**
207:      * @HandlesCommand("raffle")
208:      * @Matches("/^raffle leave$/i")
209:      */
210:     public function raffleLeaveCommand($message, $channel, $sender, $sendto, $args) {
211:         if (!$this->raffles["running"]) {
212:             $msg = "There is no active raffle.";
213:             $sendto->reply($msg);
214:             return;
215:         }
216: 
217:         if (!isset( $this->raffles["rafflees"][$sender])) {
218:             $msg = "You are not currently signed up for the raffle.";
219:             $sendto->reply($msg);
220:             return;
221:         }
222: 
223:         unset($this->raffles["rafflees"][$sender]);
224:         $msg = "$sender has left the raffle.";
225:         $this->raffles["sendto"]->reply($msg);
226:     }
227:     
228:     /**
229:      * @Event("timer(2sec)")
230:      * @Description("Checks to see if raffle is over")
231:      */
232:     public function checkRaffleEvent($eventObj) {
233:         if (!$this->raffles["running"]) {
234:             // no raffle running, do nothing
235:         } else if (time() < $this->raffles["nextmsgtime"]) {
236:             // not time to display another reminder yet
237:         } else if ($this->raffles["time"] == $this->raffles["nextmsgtime"]) {
238:             // if there is no time left or we even skipped over the time, end raffle
239:             $this->endraffle();
240:         } else {
241:             $this->showRaffleReminder();
242:         }
243:     }
244:     
245:     function endraffle() {
246:         // just to make sure there is a raffle to end
247:         if (!$this->raffles["running"]) {
248:             return;
249:         }
250:         // indicate that the raffle is over
251:         $this->raffles["running"] = false;
252: 
253:         $item = $this->raffles["item"];
254:         $count = $this->raffles["count"];
255:         $rafflees = array_keys($this->raffles["rafflees"]);
256:         $rafflees_num = count($rafflees);
257: 
258:         if (0 == $rafflees_num) {
259:             $msg = "No one joined the raffle, $item is free for all.";
260:             $this->raffles["lastresult"] = $msg;
261: 
262:             $this->raffles["sendto"]->reply($msg);
263:             return;
264:         }
265: 
266:         // first shuffle the names
267:         for ($i = 0; $i < 5; $i++) {
268:             shuffle($rafflees);
269:         }
270:         // roll multiple times to generate a list of winners
271:         $rollcount = 1000 * $rafflees_num;
272: 
273:         for ($i = 0; $i < $rollcount; $i++) {
274:             // roll a name out of the rafflees and add a rollcount
275:             $random_name = $rafflees[mt_rand(0, $rafflees_num - 1)];
276:             $this->raffles["rafflees"][$random_name] ++;
277:         }
278: 
279:         // sort the list depending on roll results
280:         arsort($this->raffles["rafflees"]);
281: 
282:         $blob = '';
283:         if (1 == $count) {
284:             $blob .= "Rolled $rollcount times for $item.\n \n Winner:";
285:         } else {
286:             $blob .= "Rolled $rollcount times for $item (count: $count).\n \n Winners:";
287:         }
288: 
289:         $i = 0;
290:         forEach ($this->raffles["rafflees"] as $char => $rolls) {
291:             $i++;
292:             $blob .= "\n$i. $char got $rolls rolls.";
293:             if ($i == $count) {
294:                 $blob .= "\n-------------------------\n Unlucky:";
295:             }
296:         }
297:         $results = $this->text->makeBlob("Detailed results", $blob);
298: 
299:         if (1 == $count) {
300:             $msg = "The raffle for $item is over. Winner: ";
301:         } else {
302:             $msg = "The raffle for $item (count: $count) is over. Winners: ";
303:         }
304: 
305:         $i = 0;
306:         forEach ($this->raffles["rafflees"] as $char => $rolls) {
307:             $i++;
308:             $msg .= "{$char}!";
309:             if ($i != $count) {
310:                 $msg .= ", ";
311:             } else {
312:                 break;
313:             }
314:         }
315:         $msg .= " Congratulations. $results";
316:         $this->raffles["lastresult"] = $msg;
317:         $this->raffles["sendto"]->reply($msg);
318:     }
319: 
320:     function getNextTime($endtime) {
321:         $tleft = $endtime - time();
322:         if ($tleft <= 0) {
323:             $ret = false;
324:         } else if ($tleft <= 30) {
325:             $ret = $endtime;
326:         } else if ($tleft <= 60) {
327:             $ret = $endtime - 30;
328:         } else if ($tleft <= 120) {
329:             $ret = $endtime - 60;
330:         } else {
331:             $ret = $endtime - floor(($tleft - 30) / 60) * 60;
332:         }
333:         return $ret;
334:     }
335: 
336:     function showRaffleReminder() {
337:         // there is a raffle running
338:         $time_string = $this->util->unixtimeToReadable($this->raffles["time"] - $this->raffles["nextmsgtime"]);
339:         $item = $this->raffles["item"];
340:         $count = $this->raffles["count"];
341: 
342:         // generate an info window
343:         $blob = "<header2>Current Members:<end>";
344:         forEach (array_keys($this->raffles["rafflees"]) as $tempName) {
345:             $blob .= "\n$tempName";
346:         }
347:         if (count($this->raffles["rafflees"]) == 0) {
348:             $blob .= "No entrants yet.";
349:         }
350:         
351:         $joinLink = $this->text->makeChatcmd("here", "/tell <myname> raffle join");
352:         $leaveLink = $this->text->makeChatcmd("here", "/tell <myname> raffle leave");
353: 
354:         $blob .= "\n\nClick $joinLink to join the raffle!";
355:         $blob .= "\nClick $leaveLink if you wish to leave the raffle.";
356:         $blob .= "\n\n Time left: $time_string.";
357: 
358:         $link = $this->text->makeBlob("Raffle Info", $blob);
359:         if (1 < $count) {
360:             $msg = "Reminder: Raffle for $item (count: $count) has $time_string left. $link";
361:         } else {
362:             $msg = "Reminder: Raffle for $item has $time_string left. $link";
363:         }
364: 
365:         $this->raffles["sendto"]->reply($msg);
366:         $this->raffles["nextmsgtime"] = $this->getNextTime($this->raffles["time"]);
367:     }
368: }
369: 
Budabot 4 Docs API documentation generated by ApiGen