protected function caps(Bot $bot) { if (!isset($this->caps[$bot->message['usernameraw']])) { $this->caps[$bot->message['usernameraw']] = array('kills' => 0, 'counter' => 0, 'lastreset' => 0); } if ($this->caps[$bot->message['usernameraw']]['lastreset'] < (time() - 3600)) { if ($this->caps[$bot->message['usernameraw']]['kills'] > 0) $this->caps[$bot->message['usernameraw']]['kills']--; } if ($this->caps[$bot->message['usernameraw']]['lastreset'] < (time() - 120)) { if ($this->caps[$bot->message['usernameraw']]['counter'] > 0) $this->caps[$bot->message['usernameraw']]['counter']--; $this->caps[$bot->message['usernameraw']]['lastreset'] = time(); } $capscount = 0; // don't count whitespace $message = preg_replace('~[\s!?\.]~', '', $bot->message['text']); $charcount = strlen($message); $chars = str_split($bot->message['text']); foreach ($chars as $char) { if (preg_match('~[A-Z]~', $char)) $capscount++; } if (strlen($message) < 6 || ($capscount / $charcount * 100) < $this->config->config['capspercent']) return; $this->caps[$bot->message['usernameraw']]['counter']++; $bot->queue('/whisper "'.$bot->message['usernameraw'].'" '.Core::language()->antispam_no_caps); if ($this->caps[$bot->message['usernameraw']]['counter'] > 2) { $this->caps[$bot->message['usernameraw']]['counter'] = 0; $bot->queue('/tmute '.$bot->message['usernameraw'].' '.pow(2, $this->caps[$bot->message['usernameraw']]['kills']++)); } }
public function handle(Bot $bot) { if ($bot->message['id'] % 500 == 0) $this->cache = array(); if ($bot->message['usernameraw'] == NAME) return; if (substr($bot->message['text'], 0, 8) == '!google ') { $data = $this->search(substr($bot->message['text'], 8)); $bot->queue('Google ['.substr($bot->message['text'], 8).']: http://google.de/search?q='.rawurlencode(substr($bot->message['text'], 8)).' '.Core::language()->get('google_number', array('{number}' => number_format($data['responseData']['cursor']['estimatedResultCount'], 0, Core::language()->decimal_point, Core::language()->thousand_separator)))); $bot->queue('#1: '.strip_tags($data['responseData']['results'][0]['title']).': '.$data['responseData']['results'][0]['unescapedUrl']); } }
public function handle(Bot $bot) { if ($bot->message['id'] % 500 == 0) $this->config->write(); if ($bot->message['type'] == Bot::JOIN) { $userID = $bot->lookUpUserID(); if (isset($this->config->config[$userID]) && (!isset($this->coolDown[$userID]) || ($this->coolDown[$userID] + 5 * 60) < time())) { $bot->queue('['.$bot->message['usernameraw'].'] '.substr($this->config->config[$userID], 0, 250)); $this->coolDown[$userID] = time(); } } else if (substr(Module::removeWhisper($bot->message['text']), 0, 7) == '!quote ') { $username = substr(Module::removeWhisper($bot->message['text']), 7); $userID = $bot->lookUpUserID($username); if ($userID) { if (isset($this->config->config[$userID])) { $bot->queue('/whisper "'.$bot->message['usernameraw'].'" ['.$username.'] '.$this->config->config[$userID]); } else { $bot->queue('/whisper "'.$bot->message['usernameraw'].'" '.Core::language()->quotes_noquote); } } else { $bot->queue('/whisper "'.$this->message['usernameraw'].'" '.Core::language()->get('user_not_found', array('{user}' => $username))); } } else if (substr(Module::removeWhisper($bot->message['text']), 0, 10) == '!setquote ') { $this->config->config[$bot->lookUpUserID()] = substr(Module::removeWhisper($bot->message['text']), 10); $bot->success(); } else if (Module::removeWhisper($bot->message['text']) == '!delquote') { unset($this->config->config[$bot->lookUpUserID()]); $bot->success(); } else if (substr(Module::removeWhisper($bot->message['text']), 0, 11) == '!wipequote ') { if (Core::compareLevel($bot->lookUpUserID(), 'quote.wipe')) { $username = substr(Module::removeWhisper($bot->message['text']), 11); $userID = $bot->lookUpUserID($username); if ($userID > 0) { unset($this->config->config[$userID]); $bot->success(); } else { $bot->queue('/whisper "'.$this->message['usernameraw'].'" '.Core::language()->get('user_not_found', array('{user}' => $username))); } } else { $bot->denied(); } } }
public function handle(Bot $bot) { if (substr($bot->message['text'], 0, 7) != 'apt-get') return; $text = explode(' ', substr($bot->message['text'], 8), 2); switch ($text[0]) { case 'moo': $bot->queue('...."Have you mooed today?"...'); break; case 'install': if (!Core::compareLevel($bot->lookUpUserID(), 'op.load')) return $bot->denied(); if (stripos($text[1], '--reinstall') !== -1) { $text[1] = str_replace('--reinstall', '', $text[1]); Core::log()->info = $bot->message['usernameraw'].' reloaded a module'; $result = Core::reloadModule(trim($text[1])); } else { Core::log()->info = $bot->message['usernameraw'].' loaded a module'; $result = Core::loadModule(trim($text[1])); } if (!is_int($result)) { $bot->success(); } else { $name = 'module_error_'.$result; $bot->queue('/whisper "'.$bot->message['usernameraw'].'" '.Core::language()->$name); } break; case 'remove': case 'purge': $text[1] = str_replace('--purge', '', $text[1]); if (!Core::compareLevel($bot->lookUpUserID(), 'op.load')) return $bot->denied(); Core::log()->info = $bot->message['usernameraw'].' unloaded a module'; $result = Core::unloadModule(trim($text[1])); if (!is_int($result)) { $bot->success(); } else { $name = 'module_error_'.$result; $bot->queue('/whisper "'.$bot->message['usernameraw'].'" '.Core::language()->$name); } break; case 'upgrade': if (!Core::compareLevel($bot->lookUpUserID(), 'op.load')) return $bot->denied(); $modules = Core::getModules(); foreach ($modules as $module => $tmp) Core::reloadModule($module); break; } }
public function handle(Bot $bot) { if (Module::removeWhisper($bot->message['text']) == '!mycolor') { preg_match_all('/color: #[0-9a-fA-F]{6}/', $bot->message['username'], $matches); $bot->queue('/whisper "'.$bot->message['usernameraw'].'" /color '.substr($matches[0][0], 7).' '.substr($matches[0][count($matches[0])-1], 7)); } else if ($bot->message['text'] == '!info') { if (Core::compareLevel($bot->lookUpUserID(), 'util.info')) { $bot->queue(Core::language()->util_information.':'); $bot->queue(Core::language()->util_since.": ".date('d.m.Y H:i:s', TIME)); $bot->queue(Core::language()->util_got.": ".$bot->messageCount.' ('.round($bot->messageCount / (time() - TIME) * 60, 4).'/m)'); $bot->queue(Core::language()->util_sent.": ".$bot->sendCount.' ('.round($bot->sendCount / (time() - TIME) * 60, 4).'/m)'); } else { $bot->denied(); } } }
public function handle(Bot $bot) { if (Module::removeWhisper($bot->message['text']) == '!shutdown') { if (!Core::compareLevel($bot->lookUpUserID(), 'op.shutdown')) return $bot->denied(); Core::log()->info = $bot->message['usernameraw'].' shutted the bot down'; $bot->shutdown(); } else if (Module::removeWhisper($bot->message['text']) == '!restart') { if (!Core::compareLevel($bot->lookUpUserID(), 'op.shutdown')) return $bot->denied(); Core::log()->info = $bot->message['usernameraw'].' restarted the bot'; $bot->shutdown(SIGUSR1); } else if (substr(Module::removeWhisper($bot->message['text']), 0, 5) == '!say ') { if (!Core::compareLevel($bot->lookUpUserID(), 500)) return $bot->denied(); $bot->queue(substr(Module::removeWhisper($bot->message['text']), 5)); } else if (Module::removeWhisper($bot->message['text']) == '!loaded') { if (!Core::compareLevel($bot->lookUpUserID(), 'op.load')) return $bot->denied(); $bot->queue('/whisper "'.$bot->message['usernameraw'].'" '.Core::language()->op_loaded.': '.implode(', ', array_keys(Core::getModules()))); } else if (substr(Module::removeWhisper($bot->message['text']), 0, 6) == '!join ') { if (!Core::compareLevel($bot->lookUpUserID(), 'op.join')) return $bot->denied(); $bot->getConnection()->join(substr(Module::removeWhisper($bot->message['text']), 6)); $bot->success(); } else if (Module::removeWhisper($bot->message['text']) == '!perms') { if (!Core::compareLevel($bot->lookUpUserID(), 500)) return $bot->denied(); $perms = Core::permission()->getNodes(); ksort($perms); $permString = array(); foreach ($perms as $name => $level) { $permString[] = $name.': '.$level; } $bot->queue('/whisper "'.$bot->message['usernameraw'].'" '.Core::language()->op_perms.': '.implode(', ', $permString)); } else if (Module::removeWhisper($bot->message['text']) == '!rooms') { if (!Core::compareLevel($bot->lookUpUserID(), 'op.join')) return $bot->denied(); $rooms = $bot->getConnection()->getRooms(); $roomString = array(); foreach ($rooms as $id => $name) { $roomString[] = $name.': '.$id; } $bot->queue('/whisper "'.$bot->message['usernameraw'].'" '.Core::language()->op_rooms.': '.implode(', ', $roomString)); } }
public function handle(Bot $bot) { if ($bot->message['id'] % 500 == 0) $this->cache = array(); if ($bot->message['usernameraw'] == NAME) return; if (preg_match_all('~http://(?:.+\.)?youtu(?:\.be/|be\.com/watch\?(?:.*)v=)([a-zA-Z0-9_-]+?)~U', $bot->message['text'], $matches)) foreach ($matches[1] as $id) { $title = $this->lookUp($id); if ($title !== false) { $bot->queue('Youtube ['.$id.']: '.$title); } } }
public function handle(Bot $bot) { if ($bot->message['id'] % 500 == 0) $this->config->write(); if (substr($bot->message['text'], 0, 1) == '-') { if (isset($this->config->config[substr($bot->message['text'], 1)])) { $bot->queue($this->config->config[substr($bot->message['text'], 1)]); } } else if (substr(Module::removeWhisper($bot->message['text']), 0, 5) == '!dic ') { if (Core::compareLevel($bot->lookUpUserID(), 'dic.add')) { $data = explode(' ', substr(Module::removeWhisper($bot->message['text']), 5), 2); if (substr($data[1], 0, 1) == '!') return $bot->denied(); $this->config->config[$data[0]] = $data[1]; Core::log()->info = $bot->message['usernameraw'].' added '.$data[0].' to dictionary'; $bot->success(); } else { $bot->denied(); } } else if (substr(Module::removeWhisper($bot->message['text']), 0, 8) == '!deldic ') { if (Core::compareLevel($bot->lookUpUserID(), 'dic.add')) { $data = substr(Module::removeWhisper($bot->message['text']), 8); unset($this->config->config[$data]); $bot->success(); } else { $bot->denied(); } } else if (Module::removeWhisper($bot->message['text']) == '!listdic') { if (Core::compareLevel($bot->lookUpUserID(), 'dic.list')) { $entries = array_keys($this->config->config); sort($entries); $bot->queue('/whisper "'.$bot->message['usernameraw'].'" '.Core::language()->dic_listdic.': '.implode(', ', $entries)); } else { $bot->denied(); } } }
public function handle(Bot $bot) { if ($bot->message['id'] % 500 == 0) $this->config->write(); if ($bot->message['type'] == Bot::JOIN) { $userID = $bot->lookUpUserID(); if (!isset($this->config->config[$userID])) { $this->config->config[$userID] = array('got' => 0, 'has' => 3, 'lastjoin' => 0, 'joins' => 0); } if ($this->config->config[$userID]['lastjoin'] + 86400 < time()) { $this->config->config[$userID]['lastjoin'] = time(); $this->config->config[$userID]['joins']++; if ($this->config->config[$userID]['joins'] >= 3) { $this->config->config[$userID]['joins'] = 0; $this->config->config[$userID]['has']++; $bot->queue('/whisper "'.$bot->message['usernameraw'].'" Du kannst jetzt '.$this->config->config[$userID]['has'].' Rosen verteilen: !rose Benutzername'); } } } if (substr($t = Module::removeWhisper($bot->message['text']), 0, 6) == '!roses') { if ($t == '!roses') { $userID = $bot->lookUpUserID(); $username = $bot->message['usernameraw']; } else { $username = substr($t, 7); $userID = $bot->lookUpUserID($username); } if (!isset($this->config->config[$userID])) { $this->config->config[$userID] = array('got' => 0, 'has' => 3, 'lastjoin' => 0, 'joins' => 0); } $bot->queue('/whisper "'.$bot->message['usernameraw'].'" '.$username.' hat bisher '.$this->config->config[$userID]['got']. ' Rosen erhalten und kann noch '.$this->config->config[$userID]['has'].' Stück verteilen.'); } else if (substr($bot->message['text'], 0, 6) == '!rose ') { $userID = $bot->lookUpUserID(); if (!isset($this->config->config[$userID])) { $this->config->config[$userID] = array('got' => 0, 'has' => 3, 'lastjoin' => 0, 'joins' => 0); } if ($this->config->config[$userID]['has'] > 0) { $username = substr($bot->message['text'], 6); $to = $bot->lookUpUserID($username); if ($to) { if ($to != $userID) { if (!isset($this->config->config[$to])) { $this->config->config[$to] = array('got' => 0, 'has' => 3, 'lastjoin' => 0, 'joins' => 0); } $this->config->config[$to]['got']++; $this->config->config[$userID]['has']--; $bot->queue('['.$bot->message['usernameraw'].'] hat eine Rose an '.$username.' gegeben'); } else { $bot->queue('/whisper "'.$bot->message['usernameraw'].'" Du kannst dir nicht selber eine Rose geben'); } } else { $bot->queue('/whisper "'.$bot->message['usernameraw'].'" '.Core::language()->get('user_not_found', array('{user}' => $username))); } } else { $bot->queue('/whisper "'.$bot->message['usernameraw'].'" Du hast keine Rosen'); } } }
public function handle(Bot $bot) { if ($this->rouletteBullet == 0) $this->rouletteBullet = rand(1,6); if (preg_match('~^\.\.\.+$~', $bot->message['text'])) { $bot->queue('/me '.Core::language()->toys_pacman); } if (Module::removeWhisper($bot->message['text']) == '!ping') { $bot->queue('/whisper "'.$bot->message['usernameraw'].'" !pong'); } else if (substr($bot->message['text'], 0, 5) == '!dice') { $command = substr($bot->message['text'], 5); $command = explode('d', $command, 2); $command[0] = min(10, $command[0]); if (count($command) > 1) { while ($command[0]--) { $results[] = rand(1, $command[1]); } } else { $results[] = rand(1,6); } sort($results); $bot->queue(implode(', ', $results).' wurde von '.$bot->message['usernameraw'].' gewuerfelt'); } else if ($bot->message['text'] == '!kuschel') { $bot->queue('/me kuschelt sich an '.$bot->message['usernameraw']); } else if (substr($bot->message['text'], 0, 2) == '!8') { $data = str_split(substr(strtolower($bot->message['text']), 2)); $sum = 0; foreach($data as $char) $sum += ord($char); $send = 'toys_eight_'.($sum % self::$eight); $bot->queue('['.$bot->message['usernameraw'].'] '.Core::language()->$send); } else if (substr($bot->message['text'], 0, 5) == '!user') { $text = str_split(substr(strtolower($bot->message['text']), 5)); $sum = 0; foreach($text as $char) $sum += ord($char); $send = $bot->data['users'][$sum % count($bot->data['users'])]['usernameraw']; $bot->queue('['.$bot->message['usernameraw'].'] '.$send); } else if ($bot->message['type'] == Bot::MODERATE && preg_match('~bis [0-3][0-9].[01][0-9].([0-9]+)~', $bot->message['text'], $matches)) { if ($matches[1] > (date('Y') + 9000)) { $bot->queue('Its over ninethousand!'); } } else if ($bot->message['text'] == '!shot' || $bot->message['text'] == '!spin') { if ($bot->message['text'] == '!spin') { $this->rouletteBullet = rand(1,6); $cost = 4; $message = '['.$bot->message['usernameraw'].'] dreht den Zylinder und drückt ab…'; } else { $cost = 1; $message = '['.$bot->message['usernameraw'].'] drückt ab…'; } if (!isset($this->rouletteStatus[$bot->message['usernameraw']])) $this->rouletteStatus[$bot->message['usernameraw']] = 0; $this->rouletteBullet--; if ($this->rouletteBullet == 0) { $this->rouletteStatus[$bot->message['usernameraw']] += $cost; $bot->queue($message.'Boooom'); $bot->queue('/tmute '.$bot->message['usernameraw'].' '.($this->rouletteStatus[$bot->message['usernameraw']])); $this->rouletteBullet = rand(1,6); } else $bot->queue($message.'Klack, nichts passiert'); } }
protected function end(Bot $bot) { $bot->queue('Die Abstimmung ist beendet'); $bot->queue('Es haben '.$this->yes.' Leute für Ja und '.$this->no.' für Nein gestimmt'); $this->reset(); }