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;
  4: 
  5: /**
  6:  * @Instance
  7:  */
  8: class Util {
  9: 
 10:     /** @Inject */
 11:     public $chatBot;
 12:     
 13:     /** @Logger */
 14:     public $logger;
 15: 
 16:     const DATETIME = "d-M-Y H:i T";
 17: 
 18:     public function bytesConvert($bytes) {
 19:         $ext = array('B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB');
 20:         $unitCount = 0;
 21:         for ($max = count($ext) - 1; $bytes >= 1024 && $unitCount < $max; $unitCount++) {
 22:             $bytes /= 1024;
 23:         }
 24:         return round($bytes, 2) ." ". $ext[$unitCount];
 25:     }
 26: 
 27:     public function unixtimeToReadable($time, $showSeconds = true) {
 28:         if ($time == 0) {
 29:             return '0 secs';
 30:         }
 31: 
 32:         $units = [
 33:             "day" => 86400,
 34:             "hr" => 3600,
 35:             "min" => 60,
 36:             "sec" => 1
 37:         ];
 38: 
 39:         $timeshift = '';
 40:         forEach ($units as $unit => $seconds) {
 41:             if ($time > 0) {
 42:                 $length = floor($time / $seconds);
 43:             } else {
 44:                 $length = ceil($time / $seconds);
 45:             }
 46:             if ($unit != "sec" || $showSeconds || $timeshift == '') {
 47:                 if ($length > 1) {
 48:                     $timeshift .= $length . " " . $unit . "s "; 
 49:                 } else if ($length == 1) {
 50:                     $timeshift .= $length . " " . $unit . " ";
 51:                 }
 52:             }
 53:             $time = $time % $seconds;
 54:         }
 55: 
 56:         return trim($timeshift);
 57:     }
 58: 
 59:     public function parseTime($budatime) {
 60:         $unixtime = 0;
 61: 
 62:         $matches = array();
 63:         $pattern = '/([0-9]+)([a-z]+)/';
 64:         preg_match_all($pattern, $budatime, $matches, PREG_SET_ORDER);
 65: 
 66:         forEach ($matches as $match) {
 67:             switch ($match[2]) {
 68:                 case 'y':
 69:                 case 'yr':
 70:                 case 'year':
 71:                 case 'years':
 72:                     $unixtime += $match[1] * 31536000;
 73:                     break;
 74:                 case 'mo':
 75:                 case 'month':
 76:                 case 'months':
 77:                     $unixtime += $match[1] * 2592000;
 78:                     break;
 79:                 case 'weeks':
 80:                 case 'week':
 81:                 case 'w':
 82:                     $unixtime += $match[1] * 604800;
 83:                     break;
 84:                 case 'days':
 85:                 case 'day':
 86:                 case 'd':
 87:                     $unixtime += $match[1] * 86400;
 88:                     break;
 89:                 case 'hours':
 90:                 case 'hour':
 91:                 case 'hrs':
 92:                 case 'hr':
 93:                 case 'h':
 94:                     $unixtime += $match[1] * 3600;
 95:                     break;
 96:                 case 'mins':
 97:                 case 'min':
 98:                 case 'm':
 99:                     $unixtime += $match[1] * 60;
100:                     break;
101:                 case 'secs':
102:                 case 'sec':
103:                 case 's':
104:                     $unixtime += $match[1];
105:                     break;
106:                 default:
107:                     return 0;
108:             }
109:         }
110: 
111:         return $unixtime;
112:     }
113: 
114:     /**
115:      * Takes two version numbers.  Returns 1 if the first is greater than the second.
116:      * Returns -1 if the second is greater than the first.  Returns 0 if they are equal.
117:      */
118:     public function compareVersionNumbers($ver1, $ver2) {
119:         $ver1Array = explode('.', $ver1);
120:         $ver2Array = explode('.', $ver2);
121: 
122:         for ($i = 0; $i < count($ver1Array) && $i < count($ver2Array); $i++) {
123:             if ($ver1Array[$i] > $ver2Array[$i]) {
124:                 return 1;
125:             } else if ($ver1Array[$i] < $ver2Array[$i]) {
126:                 return -1;
127:             }
128:         }
129: 
130:         if (count($ver1Array) > count($ver2Array)) {
131:             return 1;
132:         } else if (count($ver1Array) < count($ver2Array)) {
133:             return -1;
134:         } else {
135:             return 0;
136:         }
137:     }
138: 
139:     /**
140:      * @name: getProfessionName
141:      * @description: returns the full profession name given the search string passed in
142:      */
143:     public function getProfessionName($search) {
144:         $search = strtolower($search);
145:         switch ($search) {
146:             case "adv":
147:             case "advy":
148:             case "adventurer":
149:                 $prof = "Adventurer";
150:                 break;
151:             case "agent":
152:                 $prof = "Agent";
153:                 break;
154:             case "crat":
155:             case "bureaucrat":
156:                 $prof = "Bureaucrat";
157:                 break;
158:             case "doc":
159:             case "doctor":
160:                 $prof = "Doctor";
161:                 break;
162:             case "enf":
163:             case "enfo":
164:             case "enforcer":
165:                 $prof = "Enforcer";
166:                 break;
167:             case "eng":
168:             case "engi":
169:             case "engy":
170:             case "engineer":
171:                 $prof = "Engineer";
172:                 break;
173:             case "fix":
174:             case "fixer":
175:                 $prof = "Fixer";
176:                 break;
177:             case "keep":
178:             case "keeper":
179:                 $prof = "Keeper";
180:                 break;
181:             case "ma":
182:             case "martial":
183:             case "martialartist":
184:             case "martial artist":
185:                 $prof = "Martial Artist";
186:                 break;
187:             case "mp":
188:             case "meta":
189:             case "metaphysicist":
190:             case "meta-physicist":
191:                 $prof = "Meta-Physicist";
192:                 break;
193:             case "nt":
194:             case "nano":
195:             case "nanotechnician":
196:             case "nano-technician":
197:                 $prof = "Nano-Technician";
198:                 break;
199:             case "sol":
200:             case "sold":
201:             case "soldier":
202:                 $prof = "Soldier";
203:                 break;
204:             case "tra":
205:             case "trad":
206:             case "trader":
207:                 $prof = "Trader";
208:                 break;
209:             case "shade":
210:                 $prof = "Shade";
211:                 break;
212:             default:
213:                 $prof = '';
214:         }
215: 
216:         return $prof;
217:     }
218: 
219:     public function getProfessionAbbreviation($profession) {
220:         switch ($profession) {
221:             case "Adventurer":
222:                 $prof = "Adv";
223:                 break;
224:             case "Agent":
225:                 $prof = "Agent";
226:                 break;
227:             case "Bureaucrat":
228:                 $prof = "Crat";
229:                 break;
230:             case "Doctor":
231:                 $prof = "Doc";
232:                 break;
233:             case "Enforcer":
234:                 $prof = "Enf";
235:                 break;
236:             case "Engineer":
237:                 $prof = "Eng";
238:                 break;
239:             case "Fixer":
240:                 $prof = "Fixer";
241:                 break;
242:             case "Keeper":
243:                 $prof = "Keeper";
244:                 break;
245:             case "Martial Artist":
246:                 $prof = "MA";
247:                 break;
248:             case "Meta-Physicist":
249:                 $prof = "MP";
250:                 break;
251:             case "Nano-Technician":
252:                 $prof = "NT";
253:                 break;
254:             case "Soldier":
255:                 $prof = "Sol";
256:                 break;
257:             case "Trader":
258:                 $prof = "Trader";
259:                 break;
260:             case "Shade":
261:                 $prof = "Shade";
262:                 break;
263:             default:
264:                 $prof = "Unknown";
265:                 break;
266:         }
267: 
268:         return $prof;
269:     }
270: 
271:     /**
272:      * @name: verifyFilename
273:      * @description: returns true if filename matches budabot naming convention and false otherwise
274:      */
275:     public function verifyFilename($filename) {
276:         //Replace all \ characters with /
277:         $filename = str_replace("\\", "/", $filename);
278: 
279:         //check if the file exists
280:         forEach (array_reverse($this->chatBot->vars['module_load_paths']) as $modulePath) {
281:             if (file_exists("$modulePath/$filename")) {
282:                 return "$modulePath/$filename";
283:             }
284:         }
285:         if (file_exists("./core/$filename")) {
286:             return "./core/$filename";
287:         }
288:         if (file_exists($filename)) {
289:             return $filename;
290:         }
291:         return "";
292:     }
293: 
294:     public function getAbility($ability, $getFullName = false) {
295:         $abilities = array(
296:             'agi' => 'Agility',
297:             'int' => 'Intelligence',
298:             'psy' => 'Psychic',
299:             'sta' => 'Stamina',
300:             'str' => 'Strength',
301:             'sen' => 'Sense'
302:         );
303: 
304:         $ability = strtolower(substr($ability, 0, 3));
305: 
306:         if (isset($abilities[$ability])) {
307:             if ($getFullName) {
308:                 return $abilities[$ability];
309:             } else {
310:                 return $ability;
311:             }
312:         } else {
313:             return null;
314:         }
315:     }
316: 
317:     public function randomArrayValue($array) {
318:         return $array[rand(0, count($array) - 1)];
319:     }
320: 
321:     // checks to see if user is valid
322:     // invalid values:
323:     // $sender = -1 on 32bit
324:     // $sender = 4294967295 on 64bit
325:     // this function handles both 32 and 64 bit
326:     public function isValidSender($sender) {
327:         return (int)0xFFFFFFFF == $sender ? false : true;
328:     }
329: 
330:     // taken from: http://www.lost-in-code.com/programming/php-code/php-random-string-with-numbers-and-letters/
331:     public function genRandomString($length = 10, $characters = '0123456789abcdefghijklmnopqrstuvwxyz') {
332:         $string = '';
333:         for ($p = 0; $p < $length; $p++) {
334:             $string .= $characters[mt_rand(0, strlen($characters))];
335:         }
336:         return $string;
337:     }
338: 
339:     public function getStackTrace() {
340:         $trace = debug_backtrace();
341:         $arr1 = array();
342:         $arr2 = array();
343:         forEach ($trace as $obj) {
344:             $file = str_replace(getcwd(), "", $obj['file']);
345:             $arr1 []= "{$file}({$obj['line']})";
346:             $arr2 []= "{$obj['function']}()";
347:         }
348: 
349:         array_shift($arr2);
350: 
351:         $str = '';
352:         for ($i = 0; $i < count($arr1); $i++) {
353:             $str .= "$arr1[$i] : $arr2[$i]\n";
354:         }
355:         return $str;
356:     }
357: 
358:     /**
359:      * Finds all occurrences of multiple strings in a string and returns them in an array
360:      * with the key indicating the offset and the value indicating the string found.
361:      *
362:      * @param string   $haystack the string to search
363:      * @param array    $needles an array of strings to search for
364:      */
365:     public function strpos_r($haystack, $needles) {
366:         $seeks = array();
367:         
368:         forEach ($needles as $needle) {
369:             $search = $haystack;
370:             while ($seek = strrpos($search, $needle)) {
371:                 $seeks[$seek] = $needle;
372:                 $search = substr($search, 0, $seek);
373:             }
374:         }
375:         ksort($seeks);
376:         return $seeks;
377:     }
378:     
379:     public function date($unixtime) {
380:         return date(self::DATETIME, $unixtime);
381:     }
382:     
383:     public function endsWith($string, $test) {
384:         $strlen = strlen($string);
385:         $testlen = strlen($test);
386:         if ($testlen > $strlen) {
387:             return false;
388:         }
389:         return substr_compare($string, $test, -$testlen) === 0;
390:     }
391:     
392:     // taken from: http://stackoverflow.com/questions/834303/php-startswith-and-endswith-functions
393:     public function startsWith($haystack, $needle) {
394:         return !strncmp($haystack, $needle, strlen($needle));
395:     }
396:     
397:     public function stripColors($msg) {
398:         $msg = preg_replace("~<font color=#.{6}>~", "", $msg);
399:         $msg = preg_replace("~</font>~", "", $msg);
400:         return $msg;
401:     }
402:     
403:     public function generateQueryFromParams($params, $column) {
404:         $queryParams = array();
405:         $first = true;
406:         forEach ($params as $key => $value) {
407:             if ($value[0] == "-" && strlen($value) > 1) {
408:                 $value = substr($value, 1);
409:                 $op = "NOT LIKE";
410:             } else {
411:                 $op = "LIKE";
412:             }
413:             if ($first) {
414:                 $query .= "$column $op ?";
415:                 $first = false;
416:             } else {
417:                 $query .= " AND $column $op ?";
418:             }
419:             $queryParams []= '%' . $value . '%';
420:         }
421:         return array($query, $queryParams);
422:     }
423: 
424:     // taken from http://php.net/manual/en/function.usort.php
425:     public function mergesort(&$array, $cmp_function) {
426:         // Arrays of size < 2 require no action.
427:         if (count($array) < 2) {
428:             return;
429:         }
430:         // Split the array in half
431:         $halfway = count($array) / 2;
432:         $array1 = array_slice($array, 0, $halfway);
433:         $array2 = array_slice($array, $halfway);
434:         // Recurse to sort the two halves
435:         $this->mergesort($array1, $cmp_function);
436:         $this->mergesort($array2, $cmp_function);
437:         // If all of $array1 is <= all of $array2, just append them.
438:         if ($cmp_function(end($array1), $array2[0]) < 1) {
439:             $array = array_merge($array1, $array2);
440:             return;
441:         }
442:         // Merge the two sorted arrays into a single sorted array
443:         $array = array();
444:         $ptr1 = $ptr2 = 0;
445:         while ($ptr1 < count($array1) && $ptr2 < count($array2)) {
446:             if ($cmp_function($array1[$ptr1], $array2[$ptr2]) < 1) {
447:                 $array[] = $array1[$ptr1++];
448:             } else {
449:                 $array[] = $array2[$ptr2++];
450:             }
451:         }
452:         // Merge the remainder
453:         while ($ptr1 < count($array1)) {
454:             $array[] = $array1[$ptr1++];
455:         }
456:         while ($ptr2 < count($array2)) {
457:             $array[] = $array2[$ptr2++];
458:         }
459:         return;
460:     }
461: 
462:     public function interpolate($x1, $x2, $y1, $y2, $x) {
463:         if ($x1 == $x2) {
464:             return $y2;
465:         }
466:         $result = ($y2 - $y1) / ($x2 - $x1) * ($x - $x1) + $y1;
467:         $result = round($result, 0);
468:         return $result;
469:     }
470: 
471:     public function mapFilterCombine($arr, $glue, $func) {
472:         $newArr = array();
473:         forEach ($arr as $key => $value) {
474:             $result = call_user_func($func, $key, $value);
475:             if ($result !== null) {
476:                 $newArr []= $result;
477:             }
478:         }
479:         return implode($glue, $newArr);
480:     }
481: 
482:     public function getFilesInDirectory($path) {
483:         $files = array();
484:         if ($dir = dir($path)) {
485:             while (false !== ($entry = $dir->read())) {
486:                 if (!is_dir($path . "/" . $entry)) {
487:                     $files []= $entry;
488:                 }
489:             }
490:             $dir->close();
491:         }
492:         return $files;
493:     }
494: 
495:     public function getDirectoriesInDirectory($path) {
496:        return array_filter(scandir($path), function ($f) use($path) {
497:            return $f != '.' && $f != '..' && is_dir($path . DIRECTORY_SEPARATOR . $f);
498:        });
499:     }
500: 
501:     public function isInteger($input){
502:         return(ctype_digit(strval($input)));
503:     }
504: }
505: 
Budabot 4 Docs API documentation generated by ApiGen