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:  * @Instance
  7:  *
  8:  * Commands this class contains:
  9:  *  @DefineCommand(
 10:  *      command     = 'news',
 11:  *      accessLevel = 'member',
 12:  *      description = 'Shows news',
 13:  *      help        = 'news.txt'
 14:  *  )
 15:  *  @DefineCommand(
 16:  *      command     = 'news .+',
 17:  *      accessLevel = 'mod',
 18:  *      description = 'Adds, removes, stickies or unstickies a news entry',
 19:  *      help        = 'news.txt'
 20:  *  )
 21:  */
 22: class NewsController {
 23:     /** @Inject */
 24:     public $db;
 25: 
 26:     /** @Inject */
 27:     public $chatBot;
 28: 
 29:     /** @Inject */
 30:     public $settingManager;
 31: 
 32:     /** @Inject */
 33:     public $text;
 34:     
 35:     /** @Inject */
 36:     public $util;
 37: 
 38:     public $moduleName;
 39: 
 40:     /**
 41:      * @Setup
 42:      */
 43:     public function setup() {
 44:         $this->db->loadSQLFile($this->moduleName, 'news');
 45: 
 46:         $this->settingManager->add($this->moduleName, "num_news_shown", "Maximum number of news items shown", "edit", "number", "10", "5;10;15;20");
 47:     }
 48: 
 49:     public function getNews() {
 50:         $sql = "SELECT * FROM `news` WHERE deleted = 0 ORDER BY `sticky` DESC, `time` DESC LIMIT ?";
 51:         $data = $this->db->query($sql, intval($this->settingManager->get('num_news_shown')));
 52:         $msg = '';
 53:         if (count($data) != 0) {
 54:             $blob = '';
 55:             $sticky = "";
 56:             forEach ($data as $row) {
 57:                 if ($sticky != '') {
 58:                     if ($sticky != $row->sticky) {
 59:                         $blob .= "____________________________\n\n";
 60:                     } else {
 61:                         $blob .= "\n";
 62:                     }
 63:                 }
 64: 
 65:                 $blob .= "<highlight>{$row->news}<end>\n";
 66:                 $blob .= "By {$row->name} " . $this->util->date($row->time) . " ";
 67:                 $blob .= $this->text->makeChatcmd("Remove", "/tell <myname> news rem $row->id") . " ";
 68:                 if ($row->sticky == 1) {
 69:                     $blob .= $this->text->makeChatcmd("Unsticky", "/tell <myname> news unsticky $row->id")."\n";
 70:                 } else if ($row->sticky == 0) {
 71:                     $blob .= $this->text->makeChatcmd("Sticky", "/tell <myname> news sticky $row->id")."\n";
 72:                 }
 73:                 $sticky = $row->sticky;
 74:             }
 75:             $msg = $this->text->makeBlob("News [Last updated at " . $this->util->date($data[0]->time) . "]", $blob);
 76:         }
 77:         return $msg;
 78:     }
 79: 
 80:     /**
 81:      * @Event("logOn")
 82:      * @Description("Sends news to org members logging in")
 83:      */
 84:     public function logonEvent($eventObj) {
 85:         $sender = $eventObj->sender;
 86: 
 87:         if ($this->chatBot->isReady() && isset($this->chatBot->guildmembers[$sender])) {
 88:             if ($this->hasRecentNews()) {
 89:                 $this->chatBot->sendTell($this->getNews(), $sender);
 90:             }
 91:         }
 92:     }
 93:     
 94:     /**
 95:      * @Event("joinPriv")
 96:      * @Description("Sends news to players joining private channel")
 97:      */
 98:     public function privateChannelJoinEvent($eventObj) {
 99:         $sender = $eventObj->sender;
100: 
101:         if ($this->hasRecentNews()) {
102:             $this->chatBot->sendTell($this->getNews(), $sender);
103:         }
104:     }
105:     
106:     public function hasRecentNews() {
107:         $thirtyDays = time() - (86400 * 30);
108:         $row = $this->db->queryRow("SELECT * FROM `news` WHERE deleted = 0 AND time > ? LIMIT 1", $thirtyDays);
109:         return $row !== null;
110:     }
111: 
112:     /**
113:      * This command handler shows latest news.
114:      *
115:      * @HandlesCommand("news")
116:      * @Matches("/^news$/i")
117:      */
118:     public function newsCommand($message, $channel, $sender, $sendto) {
119:         $msg = $this->getNews();
120:         if ($msg == '') {
121:             $msg = "No News recorded yet.";
122:         }
123: 
124:         $sendto->reply($msg);
125:     }
126: 
127:     /**
128:      * This command handler adds a news entry.
129:      *
130:      * @HandlesCommand("news .+")
131:      * @Matches("/^news add (.+)$/si")
132:      */
133:     public function newsAddCommand($message, $channel, $sender, $sendto, $arr) {
134:         $news = $arr[1];
135:         $this->db->exec("INSERT INTO `news` (`time`, `name`, `news`, `sticky`, `deleted`) VALUES (?, ?, ?, 0, 0)", time(), $sender, $news);
136:         $msg = "News has been added successfully.";
137: 
138:         $sendto->reply($msg);
139:     }
140: 
141:     /**
142:      * This command handler removes a news entry.
143:      *
144:      * @HandlesCommand("news .+")
145:      * @Matches("/^news rem ([0-9]+)$/i")
146:      */
147:     public function newsRemCommand($message, $channel, $sender, $sendto, $arr) {
148:         $id = $arr[1];
149:         
150:         $row = $this->getNewsItem($id);
151:         if ($row === null) {
152:             $msg = "No news entry found with the ID <highlight>{$id}<end>.";
153:         } else {
154:             $this->db->exec("UPDATE `news` SET deleted = 1 WHERE `id` = ?", $id);
155:             $msg = "News entry <highlight>{$id}<end> was deleted successfully.";
156:         }
157: 
158:         $sendto->reply($msg);
159:     }
160: 
161:     /**
162:      * This command handler stickies a news entry.
163:      *
164:      * @HandlesCommand("news .+")
165:      * @Matches("/^news sticky ([0-9]+)$/i")
166:      */
167:     public function stickyCommand($message, $channel, $sender, $sendto, $arr) {
168:         $id = $arr[1];
169: 
170:         $row = $this->getNewsItem($id);
171: 
172:         if ($row->sticky == 1) {
173:             $msg = "News ID $id is already stickied.";
174:         } else {
175:             $this->db->exec("UPDATE `news` SET `sticky` = 1 WHERE `id` = ?", $id);
176:             $msg = "News ID $id successfully stickied.";
177:         }
178:         $sendto->reply($msg);
179:     }
180: 
181:     /**
182:      * This command handler unstickies a news entry.
183:      *
184:      * @HandlesCommand("news .+")
185:      * @Matches("/^news unsticky ([0-9]+)$/i")
186:      */
187:     public function unstickyCommand($message, $channel, $sender, $sendto, $arr) {
188:         $id = $arr[1];
189: 
190:         $row = $this->getNewsItem($id);
191: 
192:         if ($row->sticky == 0) {
193:             $msg = "News ID $id is not stickied.";
194:         } else if ($row->sticky == 1) {
195:             $this->db->exec("UPDATE `news` SET `sticky` = 0 WHERE `id` = ?", $id);
196:             $msg = "News ID $id successfully unstickied.";
197:         }
198:         $sendto->reply($msg);
199:     }
200:     
201:     public function getNewsItem($id) {
202:         return $this->db->queryRow("SELECT * FROM `news` WHERE `deleted` = 0 AND `id` = ?", $id);
203:     }
204: }
205: 
Budabot 4 Docs API documentation generated by ApiGen