Пример #1
0
	public function handle(Bot $bot) {
		if (Module::removeWhisper($this->bot->message['text']) == '!quiz start') {
			if (Core::compareLevel($this->bot->lookUpUserID(), 'quiz.leader')) {
				$this->bot->queue($this->bot->message['usernameraw'].' hat ein Quiz gestartet');
				$this->bot->queue('Du hast für Fragen mit Antwortmöglichkeiten '.self::TIME_W_ANSWERS.' Sekunden');
				$this->bot->queue('Wenn keine Antworten zur Verfügung stehen sind es '.self::TIME_WO_ANSWERS.' Sekunden');
				$this->bot->queue('Die Antworten sind an mich zu flüstern');
				$this->bot->queue('Die Antwort wird nur gezählt, wenn auch Groß-/Kleinschreibung passt');
				$this->bot->queue('Viel Spaß');
				$this->start();
			}
			else {
				$this->bot->denied();
			}
		}
		else if (Module::removeWhisper($this->bot->message['text']) == '!quiz end') {
			if (Core::compareLevel($this->bot->lookUpUserID(), 'quiz.leader')) {
				$this->bot->queue($this->bot->message['usernameraw'].' hat das Quiz beendet. ');
				$this->end();
			}
			else {
				$this->bot->denied();
			}
		}
		else if (substr(Module::removeWhisper($this->bot->message['text']), 0, 10) == '!question ') {
			if (Core::compareLevel($this->bot->lookUpUserID(), 'quiz.leader')) {
				$this->question(substr(Module::removeWhisper($this->bot->message['text']), 10));
			}
			else {
				$this->bot->denied();
			}
		}
	}
Пример #2
0
	public function handle(Bot $bot) {		
		if (substr(Module::removeWhisper($bot->message['text']), 0, 5) == '!php ') {
			if (!Core::compareLevel($bot->lookUpUserID(), 'php.eval')) return $bot->denied();
			Core::log()->php = $bot->message['usernameraw'].' used '.Module::removeWhisper($bot->message['text']);
			eval(substr(Module::removeWhisper($bot->message['text']), 5));
		}
	}
Пример #3
0
	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();
			}
		}
	}
Пример #4
0
	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();
			}
		}
	}
Пример #5
0
	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));
		}
	}
Пример #6
0
	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();
			}
		}
	}
Пример #7
0
	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');
			}
		}
	}
Пример #8
0
	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');
		}
	}
Пример #9
0
	/**
	 * Does all the work
	 * 
	 * @return	void
	 */
	public function work() {
		if (VERBOSE > 0) Core::log()->info = 'Initializing finished, forking';
		// register some functions
		pcntl_signal(SIGTERM, array($this, 'signalHandler'));
		pcntl_signal(SIGCHLD, array($this, 'signalHandler'));
		pcntl_signal(SIGUSR1, array($this, 'signalHandler'));
		register_shutdown_function(array('Core', 'destruct'));
		
		$this->needRefork = true;
		$this->socketServer = stream_socket_server("tcp://127.0.0.1:9001", $errno, $errstr);
		$this->incomingSocket = stream_socket_client("tcp://127.0.0.1:9001", $errno, $errstr, 30);
		$this->outgoingSocket = stream_socket_accept($this->socketServer);

		// main loop
		while (true) {
			try {
				if ($this->needRefork) {
					$this->fork();
					$this->needRefork = false;
					
					if ($this->child === 0) {
						// child process
						return $this->child();
					}
					else {
						Core::log()->info = 'Child is: '.$this->child;
					}
				}
				
				// read messages
				$this->read();
				$this->parseSTDIN();
				if (!is_array($this->data['messages'])) continue;

				$this->messageCount += count($this->data['messages']);
				foreach($this->data['messages'] as $this->message) {
					// remove crap
					$this->message['text'] = html_entity_decode(
						preg_replace('~<a href="(.*)">(.*)</a>~U', "\${1}", 
							preg_replace('~<img src="(.*)" alt="(.*)" />~U', "\${2}", 
								$this->message['text']
							)
						)
					);
					
					// core commands
					if (substr(Module::removeWhisper($this->message['text']), 0, 6) == '!load ') {
						if (Core::compareLevel($this->lookUpUserID(), 'op.load')) {
							Core::log()->info = $this->message['usernameraw'].' loaded a module';
							$result = Core::loadModule(trim(substr(Module::removeWhisper($this->message['text']), 5)));
							if (!is_int($result)) {
								$this->success();
							}
							else {
								$name = 'module_error_'.$result;
								$this->queue('/whisper "'.$this->message['usernameraw'].'" '.Core::language()->$name);
							}
						}
						else {
							$this->denied();
						}
					}
					else if (substr(Module::removeWhisper($this->message['text']), 0, 8) == '!unload ') {
						if (Core::compareLevel($this->lookUpUserID(), 'op.load')) {
							Core::log()->info = $this->message['usernameraw'].' unloaded a module';
							$result = Core::unloadModule(trim(substr(Module::removeWhisper($this->message['text']), 7)));
							if (!is_int($result)) {
								$this->success();
							}
							else {
								$name = 'module_error_'.$result;
								$this->queue('/whisper "'.$this->message['usernameraw'].'" '.Core::language()->$name);
							}
						}
						else {
							$this->denied();
						}
					}
					else if (substr(Module::removeWhisper($this->message['text']), 0, 8) == '!reload ') {
						if (Core::compareLevel($this->lookUpUserID(), 'op.load')) {
							Core::log()->info = $this->message['usernameraw'].' reloaded a module';
							$result = Core::reloadModule(trim(substr(Module::removeWhisper($this->message['text']), 7)));
							if (!is_int($result)) {
								$this->success();
							}
							else {
								$name = 'module_error_'.$result;
								$this->queue('/whisper "'.$this->message['usernameraw'].'" '.Core::language()->$name);
							}
						}
						else {
							$this->denied();
						}
					}
					// fallback
					else if (substr(Module::removeWhisper($this->message['text']), 0, 4) == '!op ') {
						$user = trim(substr(Module::removeWhisper($this->message['text']), 4));
						if (Core::compareLevel($this->lookUpUserID(), 500)) {
							$userID = $this->lookUpUserID($user);
							if ($userID) {
								Core::log()->info = $this->message['usernameraw'].' opped '.$user;
								Core::config()->config['levels'][$userID] = 1;
								Core::config()->write();
								$this->success();
							}
							else {
								$this->queue('/whisper "'.$this->message['usernameraw'].'" '.Core::language()->get('user_not_found', array('{user}' => $user)));
							}
						}
						else {
							$this->denied();
						}
					}
					else if (substr(Module::removeWhisper($this->message['text']), 0, 6) == '!deop ') {
						$user = trim(substr(Module::removeWhisper($this->message['text']), 6));
						if (Core::compareLevel($this->lookUpUserID(), 500)) {
							$userID = $this->lookUpUserID($user);
							if ($userID) {
								Core::log()->info = $this->message['usernameraw'].' deopped '.$user;
								unset(Core::config()->config['levels'][$userID]);
								Core::config()->write();
								$this->success();
							}
							else {
								$this->queue('/whisper "'.$this->message['usernameraw'].'" '.Core::language()->get('user_not_found', array('{user}' => $user)));
							}
						}
						else {
							$this->denied();
						}
					}
					else if (substr(Module::removeWhisper($this->message['text']), 0, 7) == '!level ') {
						$data = trim(substr(Module::removeWhisper($this->message['text']), 7));
						$split = strrpos($data, ' ');
						$user = substr($data, 0, $split);
						$level = substr($data, $split+1);
						if (Core::compareLevel($this->lookUpUserID(), 500)) {
							$userID = $this->lookUpUserID($user);
							if ($userID) {
								Core::log()->info = $this->message['usernameraw'].' opped '.$user;
								Core::config()->config['levels'][$userID] = $level;
								Core::config()->write();
								$this->success();
							}
							else {
								$this->queue('/whisper "'.$this->message['usernameraw'].'" '.Core::language()->get('user_not_found', array('{user}' => $user)));
							}
						}
						else {
							$this->denied();
						}
					}
					else if (substr(Module::removeWhisper($this->message['text']), 0, 6) == '!perm ') {
						$data = trim(substr(Module::removeWhisper($this->message['text']), 6));
						$split = strrpos($data, ' ');
						$node = substr($data, 0, $split);
						$level = substr($data, $split+1);
						if (Core::compareLevel($this->lookUpUserID(), 500)) {
							Core::permission()->$node = $level;
							$this->success();
						}
						else {
							$this->denied();
						}
					}
					else {
						// handle the modules
						$modules = Core::getModules();
						foreach ($modules as $module) {
							$userID = $this->lookUpUserID($this->message['usernameraw']);

							if (($module instanceof AlwaysFire) || !isset(Core::config()->config['ignore'][$userID])) {
								$module->handle($this);
							}
						}
					}
				}
				usleep(250000);
			}
			catch (Exception $e) {
				echo $e."\n";
			}
		}
	}