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:  *  - Mindrila (RK1)
  9:  *  - Derroylo (RK2)
 10:  *
 11:  * @Instance
 12:  *
 13:  * Commands this controller contains:
 14:  *  @DefineCommand(
 15:  *      command     = "logon", 
 16:  *      accessLevel = "guild", 
 17:  *      description = "Set logon message", 
 18:  *      help        = "logon_msg.txt"
 19:  *  )
 20:  *  @DefineCommand(
 21:  *      command     = "logoff", 
 22:  *      accessLevel = "guild", 
 23:  *      description = "Set logoff message", 
 24:  *      help        = "logoff_msg.txt"
 25:  *  )
 26:  *  @DefineCommand(
 27:  *      command     = "lastseen", 
 28:  *      accessLevel = "guild", 
 29:  *      description = "Shows the last logoff time of a character", 
 30:  *      help        = "lastseen.txt"
 31:  *  )
 32:  *  @DefineCommand(
 33:  *      command     = "recentseen", 
 34:  *      accessLevel = "guild", 
 35:  *      description = "Shows org members who have logged off recently", 
 36:  *      help        = "recentseen.txt"
 37:  *  )
 38:  *  @DefineCommand(
 39:  *      command     = "notify", 
 40:  *      accessLevel = "mod", 
 41:  *      description = "Adds a character to the notify list manually", 
 42:  *      help        = "notify.txt"
 43:  *  )
 44:  *  @DefineCommand(
 45:  *      command     = "updateorg", 
 46:  *      accessLevel = "mod", 
 47:  *      description = "Force an update of the org roster", 
 48:  *      help        = "updateorg.txt"
 49:  *  )
 50:  */
 51: class GuildController {
 52: 
 53:     /**
 54:      * Name of the module.
 55:      * Set automatically by module loader.
 56:      */
 57:     public $moduleName;
 58:     
 59:     /** @Inject */
 60:     public $db;
 61: 
 62:     /** @Inject */
 63:     public $chatBot;
 64:     
 65:     /** @Inject */
 66:     public $settingManager;
 67:     
 68:     /** @Inject */
 69:     public $buddylistManager;
 70:     
 71:     /** @Inject */
 72:     public $playerManager;
 73:     
 74:     /** @Inject */
 75:     public $guildManager;
 76:     
 77:     /** @Inject */
 78:     public $text;
 79:     
 80:     /** @Inject */
 81:     public $util;
 82:     
 83:     /** @Inject */
 84:     public $altsController;
 85:     
 86:     /** @Inject */
 87:     public $preferences;
 88:     
 89:     /** @Logger */
 90:     public $logger;
 91:     
 92:     /**
 93:      * @Setup
 94:      */
 95:     public function setup() {
 96:         $this->db->loadSQLFile($this->moduleName, "org_members");
 97:         
 98:         $this->settingManager->add($this->moduleName, "max_logon_msg_size", "Maximum characters a logon message can have", "edit", "number", "200", "100;200;300;400", '', "mod");
 99:         $this->settingManager->add($this->moduleName, "max_logoff_msg_size", "Maximum characters a logoff message can have", "edit", "number", "200", "100;200;300;400", '', "mod");
100:         $this->settingManager->add($this->moduleName, "first_and_last_alt_only", "Show logon/logoff for first/last alt only", "edit", "options", "0", "true;false", "1;0");
101:         
102:         $this->chatBot->guildmembers = array();
103:         $sql = "SELECT o.name, IFNULL(p.guild_rank_id, 6) AS guild_rank_id 
104:             FROM org_members_<myname> o LEFT JOIN players p ON (o.name = p.name AND p.dimension = '<dim>' AND p.guild = '<myguild>')
105:             WHERE mode != 'del'";
106:         $data = $this->db->query($sql);
107:         forEach ($data as $row) {
108:             $this->chatBot->guildmembers[$row->name] = $row->guild_rank_id;
109:         }
110:     }
111: 
112:     /**
113:      * @HandlesCommand("logon")
114:      * @Matches("/^logon$/i")
115:      */
116:     public function logonMessageShowCommand($message, $channel, $sender, $sendto, $args) {
117:         $logon_msg = $this->preferences->get($sender, 'logon_msg');
118: 
119:         if ($logon_msg === false || $logon_msg == '') {
120:             $msg = "Your logon message has not been set.";
121:         } else {
122:             $msg = "{$sender} logon: {$logon_msg}";
123:         }
124:         $sendto->reply($msg);
125:     }
126:     
127:     /**
128:      * @HandlesCommand("logon")
129:      * @Matches("/^logon (.+)$/i")
130:      */
131:     public function logonMessageSetCommand($message, $channel, $sender, $sendto, $args) {
132:         $logon_msg = $args[1];
133: 
134:         if ($logon_msg == 'clear') {
135:             $this->preferences->save($sender, 'logon_msg', '');
136:             $msg = "Your logon message has been cleared.";
137:         } else if (strlen($logon_msg) <= $this->settingManager->get('max_logon_msg_size')) {
138:             $this->preferences->save($sender, 'logon_msg', $logon_msg);
139:             $msg = "Your logon message has been set.";
140:         } else {
141:             $msg = "Your logon message is too large. Your logon message may contain a maximum of " . $this->settingManager->get('max_logon_msg_size') . " characters.";
142:         }
143:         $sendto->reply($msg);
144:     }
145:     
146:     /**
147:      * @HandlesCommand("logoff")
148:      * @Matches("/^logoff$/i")
149:      */
150:     public function logoffMessageShowCommand($message, $channel, $sender, $sendto, $args) {
151:         $logoff_msg = $this->preferences->get($sender, 'logoff_msg');
152: 
153:         if ($logoff_msg === false || $logoff_msg == '') {
154:             $msg = "Your logoff message has not been set.";
155:         } else {
156:             $msg = "{$sender} logoff: {$logoff_msg}";
157:         }
158:         $sendto->reply($msg);
159:     }
160:     
161:     /**
162:      * @HandlesCommand("logoff")
163:      * @Matches("/^logoff (.+)$/i")
164:      */
165:     public function logoffMessageSetCommand($message, $channel, $sender, $sendto, $args) {
166:         $logoff_msg = $args[1];
167: 
168:         if ($logoff_msg == 'clear') {
169:             $this->preferences->save($sender, 'logoff_msg', '');
170:             $msg = "Your logoff message has been cleared.";
171:         } else if (strlen($logoff_msg) <= $this->settingManager->get('max_logoff_msg_size')) {
172:             $this->preferences->save($sender, 'logoff_msg', $logoff_msg);
173:             $msg = "Your logoff message has been set.";
174:         } else {
175:             $msg = "Your logoff message is too large. Your logoff message may contain a maximum of " . $this->settingManager->get('max_logoff_msg_size') . " characters.";
176:         }
177:         $sendto->reply($msg);
178:     }
179:     
180:     /**
181:      * @HandlesCommand("lastseen")
182:      * @Matches("/^lastseen (.+)$/i")
183:      */
184:     public function lastseenCommand($message, $channel, $sender, $sendto, $args) {
185:         $name = ucfirst(strtolower($args[1]));
186:         $uid = $this->chatBot->get_uid($name);
187:         if (!$uid) {
188:             $msg = "Character <highlight>$name<end> does not exist.";
189:         } else {
190:             $altInfo = $this->altsController->getAltInfo($name);
191:             $onlineAlts = $altInfo->getOnlineAlts();
192: 
193:             $blob = "";
194:             forEach ($onlineAlts as $onlineAlt) {
195:                 $blob .= "<highlight>$onlineAlt<end> is currently online.\n";
196:             }
197:             
198:             $namesSql = implode(",", array_map(function($alt) { return "'$alt'";}, $altInfo->getAllAlts()));
199:             $data = $this->db->query("SELECT * FROM org_members_<myname> WHERE `name` IN ($namesSql) AND `mode` != 'del' ORDER BY logged_off DESC");
200: 
201:             forEach ($data as $row) {
202:                 if (in_array($row->name, $onlineAlts)) {
203:                     // skip
204:                     continue;
205:                 } else if ($row->logged_off == 0) {
206:                     $blob .= "<highlight>$row->name<end> has never logged on.\n";
207:                 } else {
208:                     $blob .= "<highlight>$row->name<end> last seen at " . $this->util->date($row->logged_off) . ".\n";
209:                 }
210:             }
211: 
212:             if (count($data) == 0) {
213:                 $msg .= "Character <highlight>$name<end> is not a member of the org.";
214:             } else {
215:                 $msg = $this->text->makeBlob("Last Seen Info for $altInfo->main", $blob);
216:             }
217:         }
218: 
219:         $sendto->reply($msg);
220:     }
221:     
222:     /**
223:      * @HandlesCommand("recentseen")
224:      * @Matches("/^recentseen ([a-z0-9]+)/i")
225:      */
226:     public function recentseenCommand($message, $channel, $sender, $sendto, $args) {
227:         if (!$this->isGuildBot()) {
228:             $sendto->reply("The bot must be in an org.");
229:             return;
230:         }
231: 
232:         $time = $this->util->parseTime($args[1]);
233:         if ($time < 1) {
234:             $msg = "You must enter a valid time parameter.";
235:             $sendto->reply($msg);
236:             return;
237:         }
238: 
239:         $timeString = $this->util->unixtimeToReadable($time, false);
240:         $time = time() - $time;
241: 
242:         $data = $this->db->query("SELECT case when a.main is null then o.name else a.main end as main ,o.logged_off,o.name FROM org_members_<myname> o LEFT JOIN alts a ON o.name = a.alt WHERE `mode` != 'del' AND `logged_off` > ? ORDER BY 1, o.logged_off desc, o.name", $time); 
243: 
244:         if (count($data) == 0) {
245:             $sendto->reply("No members recorded.");
246:             return;
247:         }
248: 
249:         $numinactive = 0;
250:         $highlight = 0;
251: 
252:         $blob = "Org members who have logged off within the last <highlight>{$timeString}<end>.\n\n";
253:         
254:         $prevtoon = '';
255:         forEach ($data as $row) {
256:             if ($row->main != $prevtoon) {
257:                 $prevtoon = $row->main;
258:                 $numrecentcount++;
259:                 $alts = $this->text->makeChatcmd("Alts", "/tell <myname> alts {$row->main}");
260:                 $logged = $row->logged_off;
261:                 $lasttoon = $row->name;
262: 
263:                 $character = "<pagebreak>" . $row->main . " [{$alts}]\nLast seen as [$lasttoon] on " . $this->util->date($logged) . "\n\n";
264:                 if ($highlight == 1) {
265:                     $blob .= "<highlight>$character<end>";
266:                     $highlight = 0;
267:                 } else {
268:                     $blob .= $character;
269:                     $highlight = 1;
270:                 }
271:             } 
272:         }
273:         $msg = $this->text->makeBlob("$numrecentcount recently seen org members", $blob);
274:         $sendto->reply($msg);
275:     }
276:     
277:     /**
278:      * @HandlesCommand("notify")
279:      * @Matches("/^notify (on|add) (.+)$/i")
280:      */
281:     public function notifyAddCommand($message, $channel, $sender, $sendto, $args) {
282:         $name = ucfirst(strtolower($args[2]));
283:         $uid = $this->chatBot->get_uid($name);
284: 
285:         if (!$uid) {
286:             $msg = "<highlight>{$name}<end> does not exist.";
287:             $sendto->reply($msg);
288:             return;
289:         }
290: 
291:         $row = $this->db->queryRow("SELECT mode FROM org_members_<myname> WHERE `name` = ?", $name);
292: 
293:         if ($row !== null && $row->mode != "del") {
294:             $msg = "<highlight>{$name}<end> is already on the Notify list.";
295:         } else {
296:             if ($row === null) {
297:                 $this->db->exec("INSERT INTO org_members_<myname> (`name`, `mode`) VALUES (?, 'add')", $name);
298:             } else {
299:                 $this->db->exec("UPDATE org_members_<myname> SET `mode` = 'add' WHERE `name` = ?", $name);
300:             }
301: 
302:             if ($this->buddylistManager->isOnline($name) == 1) {
303:                 $this->db->exec("INSERT INTO online (`name`, `channel`, `channel_type`, `added_by`, `dt`) VALUES (?, '<myguild>', 'guild', '<myname>', ?)", $name, time());
304:             }
305:             $this->buddylistManager->add($name, 'org');
306:             $this->chatBot->guildmembers[$name] = 6;
307:             $msg = "<highlight>{$name}<end> has been added to the Notify list.";
308:         }
309: 
310:         $sendto->reply($msg);
311:     }
312:     
313:     /**
314:      * @HandlesCommand("notify")
315:      * @Matches("/^notify (off|rem) (.+)$/i")
316:      */
317:     public function notifyRemoveCommand($message, $channel, $sender, $sendto, $args) {
318:         $name = ucfirst(strtolower($args[2]));
319:         $uid = $this->chatBot->get_uid($name);
320: 
321:         if (!$uid) {
322:             $msg = "<highlight>{$name}<end> does not exist.";
323:             $sendto->reply($msg);
324:             return;
325:         }
326: 
327:         $row = $this->db->queryRow("SELECT mode FROM org_members_<myname> WHERE `name` = ?", $name);
328: 
329:         if ($row === null) {
330:             $msg = "<highlight>{$name}<end> is not on the guild roster.";
331:         } else if ($row->mode == "del") {
332:             $msg = "<highlight>{$name}<end> has already been removed from the Notify list.";
333:         } else {
334:             $this->db->exec("UPDATE org_members_<myname> SET `mode` = 'del' WHERE `name` = ?", $name);
335:             $this->db->exec("DELETE FROM online WHERE `name` = ? AND `channel_type` = 'guild' AND added_by = '<myname>'", $name);
336:             $this->buddylistManager->remove($name, 'org');
337:             unset($this->chatBot->guildmembers[$name]);
338:             $msg = "Removed <highlight>{$name}<end> from the Notify list.";
339:         }
340: 
341:         $sendto->reply($msg);
342:     }
343:     
344:     /**
345:      * @HandlesCommand("updateorg")
346:      * @Matches("/^updateorg$/i")
347:      */
348:     public function updateorgCommand($message, $channel, $sender, $sendto, $args) {
349:         $force_update = true;
350:         $sendto->reply("Starting Roster update");
351:         $this->updateOrgRoster();
352:         $sendto->reply("Finished Roster update");
353:     }
354:     
355:     public function updateOrgRoster() {
356:         if ($this->isGuildBot()) {
357:             $this->logger->log('INFO', "Starting Roster update");
358: 
359:             // Get the guild info
360:             $org = $this->guildManager->getById($this->chatBot->vars["my_guild_id"], $this->chatBot->vars["dimension"], true);
361: 
362:             // Check if guild xml file is correct if not abort
363:             if ($org === null) {
364:                 $this->logger->log('ERROR', "Error downloading the guild roster xml file");
365:                 return;
366:             }
367: 
368:             if (count($org->members) == 0) {
369:                 $this->logger->log('ERROR', "Guild xml file has no members! Aborting roster update.");
370:                 return;
371:             }
372: 
373:             // Save the current org_members table in a var
374:             $data = $this->db->query("SELECT * FROM org_members_<myname>");
375:             if (count($data) == 0 && (count($org->members) > 0)) {
376:                 $restart = true;
377:             } else {
378:                 $restart = false;
379:                 forEach ($data as $row) {
380:                     $dbentrys[$row->name]["name"] = $row->name;
381:                     $dbentrys[$row->name]["mode"] = $row->mode;
382:                 }
383:             }
384: 
385:             $this->chatBot->ready = false;
386: 
387:             $this->db->beginTransaction();
388: 
389:             // Going through each member of the org and add or update his/her
390:             forEach ($org->members as $member) {
391:                 // don't do anything if $member is the bot itself
392:                 if (strtolower($member->name) == strtolower($this->chatBot->vars["name"])) {
393:                     continue;
394:                 }
395: 
396:                 //If there exists already data about the character just update him/her
397:                 if (isset($dbentrys[$member->name])) {
398:                     if ($dbentrys[$member->name]["mode"] == "del") {
399:                         // members who are not on notify should not be on the buddy list but should remain in the database
400:                         $this->buddylistManager->remove($member->name, 'org');
401:                         unset($this->chatBot->guildmembers[$name]);
402:                     } else {
403:                         // add org members who are on notify to buddy list
404:                         $this->buddylistManager->add($member->name, 'org');
405:                         $this->chatBot->guildmembers[$member->name] = $member->guild_rank_id;
406: 
407:                         // if member was added to notify list manually, switch mode to org and let guild roster update from now on
408:                         if ($dbentrys[$member->name]["mode"] == "add") {
409:                             $this->db->exec("UPDATE org_members_<myname> SET `mode` = 'org' WHERE `name` = ?", $member->name);
410:                         }
411:                     }
412:                 //Else insert his/her data
413:                 } else {
414:                     // add new org members to buddy list
415:                     $this->buddylistManager->add($member->name, 'org');
416:                     $this->chatBot->guildmembers[$member->name] = $member->guild_rank_id;
417: 
418:                     $this->db->exec("INSERT INTO org_members_<myname> (`name`, `mode`) VALUES (?, 'org')", $member->name);
419:                 }
420:                 unset($dbentrys[$member->name]);
421:             }
422: 
423:             $this->db->commit();
424: 
425:             // remove buddies who are no longer org members
426:             forEach ($dbentrys as $buddy) {
427:                 if ($buddy['mode'] != 'add') {
428:                     $this->db->exec("DELETE FROM online WHERE `name` = ? AND `channel_type` = 'guild' AND added_by = '<myname>'", $buddy['name']);
429:                     $this->db->exec("DELETE FROM org_members_<myname> WHERE `name` = ?", $buddy['name']);
430:                     $this->buddylistManager->remove($buddy['name'], 'org');
431:                     unset($this->chatBot->guildmembers[$buddy['name']]);
432:                 }
433:             }
434: 
435:             $this->logger->log('INFO', "Finished Roster update");
436: 
437:             if ($restart == true) {
438:                 $this->chatBot->sendGuild("Guild roster has been loaded for the first time. Restarting...");
439: 
440:                 $this->logger->log('INFO', "The bot is restarting");
441: 
442:                 sleep(5);
443: 
444:                 // in case some of the org members were already on the buddy list, we need to restart the bot
445:                 // in order to get them to appear on the online list
446:                 die();
447:             }
448:         }
449:     }
450: 
451:     /**
452:      * @Event("timer(24hrs)")
453:      * @Description("Download guild roster xml and update guild members")
454:      */
455:     public function downloadOrgRosterEvent($eventObj) {
456:         $this->updateOrgRoster();
457:     }
458:     
459:     /**
460:      * @Event("orgmsg")
461:      * @Description("Automatically update guild roster as characters join and leave the guild")
462:      */
463:     public function autoNotifyOrgMembersEvent($eventObj) {
464:         $message = $eventObj->message;
465:         if (preg_match("/^(.+) invited (.+) to your organization.$/", $message, $arr)) {
466:             $name = ucfirst(strtolower($arr[2]));
467: 
468:             if ($this->buddylistManager->isOnline("") == 1) {
469:                 $this->db->exec("INSERT INTO online (`name`, `channel`,  `channel_type`, `added_by`, `dt`) VALUES (?, '<myguild>', 'guild', '<myname>', ?)", $name, time());
470:             }
471: 
472:             $row = $this->db->queryRow("SELECT * FROM org_members_<myname> WHERE `name` = ?", $name);
473:             if ($row !== null) {
474:                 $this->db->exec("UPDATE org_members_<myname> SET `mode` = 'add' WHERE `name` = ?", $name);
475:                 $this->buddylistManager->add($name, 'org');
476:                 $this->chatBot->guildmembers[$name] = 6;
477:             } else {
478:                 $this->db->exec("INSERT INTO org_members_<myname> (`mode`, `name`) VALUES ('add', ?)", $name);
479:                 $this->buddylistManager->add($name, 'org');
480:                 $this->chatBot->guildmembers[$name] = 6;
481:             }
482: 
483:             // update character info
484:             $this->playerManager->getByName($name);
485:         } else if (preg_match("/^(.+) kicked (.+) from your organization.$/", $message, $arr) || preg_match("/^(.+) removed inactive character (.+) from your organization.$/", $message, $arr)) {
486:             $name = ucfirst(strtolower($arr[2]));
487: 
488:             $this->db->exec("UPDATE org_members_<myname> SET `mode` = 'del' WHERE `name` = ?", $name);
489:             $this->db->exec("DELETE FROM online WHERE `name` = ? AND `channel_type` = 'guild' AND added_by = '<myname>'", $name);
490: 
491:             unset($this->chatBot->guildmembers[$name]);
492:             $this->buddylistManager->remove($name, 'org');
493:         } else if (preg_match("/^(.+) just left your organization.$/", $message, $arr) || preg_match("/^(.+) kicked from organization \\(alignment changed\\).$/", $message, $arr)) {
494:             $name = ucfirst(strtolower($arr[1]));
495: 
496:             $this->db->exec("UPDATE org_members_<myname> SET `mode` = 'del' WHERE `name` = ?", $name);
497:             $this->db->exec("DELETE FROM online WHERE `name` = ? AND `channel_type` = 'guild' AND added_by = '<myname>'", $name);
498: 
499:             unset($this->chatBot->guildmembers[$name]);
500:             $this->buddylistManager->remove($name, 'org');
501:         }
502:     }
503:     
504:     /**
505:      * @Event("logOn")
506:      * @Description("Shows an org member logon in chat")
507:      */
508:     public function orgMemberLogonMessageEvent($eventObj) {
509:         $sender = $eventObj->sender;
510:         if (isset($this->chatBot->guildmembers[$sender]) && $this->chatBot->isReady()) {
511:             if ($this->settingManager->get('first_and_last_alt_only') == 1) {
512:                 // if at least one alt/main is still online, don't show logoff message
513:                 $altInfo = $this->altsController->getAltInfo($sender);
514:                 if (count($altInfo->getOnlineAlts()) > 1) {
515:                     return;
516:                 }
517:             }
518: 
519:             $whois = $this->playerManager->getByName($sender);
520: 
521:             $msg = '';
522:             if ($whois === null) {
523:                 $msg = "$sender logged on.";
524:             } else {
525:                 $msg = $this->playerManager->getInfo($whois);
526: 
527:                 $msg .= " logged on.";
528: 
529:                 $altInfo = $this->altsController->getAltInfo($sender);
530:                 if (count($altInfo->alts) > 0) {
531:                     $msg .= " " . $altInfo->getAltsBlob(false, true);
532:                 }
533:             }
534: 
535:             $logon_msg = $this->preferences->get($sender, 'logon_msg');
536:             if ($logon_msg !== false && $logon_msg != '') {
537:                 $msg .= " - " . $logon_msg;
538:             }
539: 
540:             $this->chatBot->sendGuild($msg, true);
541: 
542:             //private channel part
543:             if ($this->settingManager->get("guest_relay") == 1) {
544:                 $this->chatBot->sendPrivate($msg, true);
545:             }
546:         }
547:     }
548:     
549:     /**
550:      * @Event("logOff")
551:      * @Description("Shows an org member logoff in chat")
552:      */
553:     public function orgMemberLogoffMessageEvent($eventObj) {
554:         $sender = $eventObj->sender;
555:         if (isset($this->chatBot->guildmembers[$sender]) && $this->chatBot->isReady()) {
556:             if ($this->settingManager->get('first_and_last_alt_only') == 1) {
557:                 // if at least one alt/main is already online, don't show logoff message
558:                 $altInfo = $this->altsController->getAltInfo($sender);
559:                 if (count($altInfo->getOnlineAlts()) > 0) {
560:                     return;
561:                 }
562:             }
563: 
564:             $msg = "$sender logged off.";
565:             $logoff_msg = $this->preferences->get($sender, 'logoff_msg');
566:             if ($logoff_msg !== false && $logoff_msg != '') {
567:                 $msg .= " - " . $logoff_msg;
568:             }
569: 
570:             $this->chatBot->sendGuild($msg, true);
571: 
572:             //private channel part
573:             if ($this->settingManager->get("guest_relay") == 1) {
574:                 $this->chatBot->sendPrivate($msg, true);
575:             }
576:         }
577:     }
578:     
579:     /**
580:      * @Event("logOff")
581:      * @Description("Record org member logoff for lastseen command")
582:      */
583:     public function orgMemberLogoffRecordEvent($eventObj) {
584:         $sender = $eventObj->sender;
585:         if (isset($this->chatBot->guildmembers[$sender]) && $this->chatBot->isReady()) {
586:             $this->db->exec("UPDATE org_members_<myname> SET `logged_off` = ? WHERE `name` = ?", time(), $sender);
587:         }
588:     }
589:     
590:     public function isGuildBot() {
591:         return !empty($this->chatBot->vars["my_guild"]) && !empty($this->chatBot->vars["my_guild_id"]);
592:     }
593:     
594:     /**
595:      * @Event("connect")
596:      * @Description("Verifies that org name is correct")
597:      */
598:     public function verifyOrgNameEvent($eventObj) {
599:         if (!empty($this->chatBot->vars["my_guild"])) {
600:             if (empty($this->chatBot->vars["my_guild_id"])) {
601:                 $this->logger->log('warn', "Org name '{$this->chatBot->vars["my_guild"]}' specified, but bot does not appear to belong to an org");
602:             } else {
603:                 $gid = $this->getOrgChannelIdByOrgId($this->chatBot->vars["my_guild_id"]);
604:                 $orgChannel = $this->chatBot->gid[$gid];
605:                 if ($orgChannel != "Clan (name unknown)" && $orgChannel != $this->chatBot->vars["my_guild"]) {
606:                     $this->logger->log('warn', "Org name '{$this->chatBot->vars["my_guild"]}' specified, but bot belongs to org '$orgChannel'");
607:                 }
608:             }
609:         }
610:     }
611:     
612:     public function getOrgChannelIdByOrgId($orgId) {
613:         forEach ($this->chatBot->grp as $gid => $status) {
614:             $string = unpack("N", substr($gid, 1));
615:             if (ord(substr($gid, 0, 1)) == 3 && $string[1] == $orgId) {
616:                 return $gid;
617:             }
618:         }
619:         return null;
620:     }
621: }
622: 
623: 
Budabot 4 Docs API documentation generated by ApiGen