/** * Register commands. * All public final methods are registered. the method name is the prefix of the command * * @param Net_SmartIRC $irc */ public function register(Net_SmartIRC $irc) { // register timer to handle events from database $irc->registerTimehandler(3000, $this, 'notifyEvents'); // register all commands $methods = $this->getMethods(); foreach ($methods as $methodName => $method) { $commandName = $this->getCommandName($methodName); $regex = "^!?{$commandName}\\b"; $irc->registerActionhandler(SMARTIRC_TYPE_QUERY, $regex, $this, $methodName); } }
// ...odd things. uh huh. break; } } // load in our required libraries. require_once './includes/bootstrap.inc'; drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); require_once 'Net/SmartIRC.php'; // prevent MySQL timeouts on slow channels. db_query('SET SESSION wait_timeout = %d', 24 * 60 * 60); // initialize the bot with some sane defaults. global $irc; // allow it to be slurped by Drupal modules if need be. $bot = new drupal_wrapper(); // wrapper that integrates with Drupal hooks. $irc = new Net_SmartIRC(); // MmmmmmM. The IRC object itself. Magick happens here. $irc->setDebug(variable_get('bot_debugging', 0) ? SMARTIRC_DEBUG_ALL : SMARTIRC_DEBUG_NONE); // the (boolean) here is required, as Net_SmartIRC doesn't respect a FAPI checkbox value of 1, only TRUE. $irc->setAutoReconnect((bool) variable_get('bot_auto_reconnect', 1)); // reconnect to the server if disconnected. $irc->setAutoRetry((bool) variable_get('bot_auto_retry', 1)); // retry if a server connection fails. $irc->setChannelSyncing(TRUE); // keep a list of joined users per channel. $irc->setUseSockets(TRUE); // uses real sockets instead of fsock(). // send every message type the library supports to our wrapper class. // we can automate the creation of these actionhandlers, but not the // class methods below (only PHP 5 supports default methods easily). $irc_message_types = array('UNKNOWN', 'CHANNEL', 'QUERY', 'CTCP', 'NOTICE', 'WHO', 'JOIN', 'INVITE', 'ACTION', 'TOPICCHANGE', 'NICKCHANGE', 'KICK', 'QUIT', 'LOGIN', 'INFO', 'LIST', 'NAME', 'MOTD', 'MODECHANGE', 'PART', 'ERROR', 'BANLIST', 'TOPIC', 'NONRELEVANT', 'WHOIS', 'WHOWAS', 'USERMODE', 'CHANNELMODE', 'CTCP_REQUEST', 'CTCP_REPLY');
$_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME'] = $_SERVER['PHP_SELF']; $_SERVER['REMOTE_ADDR'] = NULL; // any values here do rather... $_SERVER['REQUEST_METHOD'] = NULL; // ...odd things. uh huh. break; } } // load in our required libraries. require_once './includes/bootstrap.inc'; drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); require_once 'Net/SmartIRC.php'; // initialize the bot with some sane defaults. global $irc; $bot = new drupal_wrapper(); $irc = new Net_SmartIRC(); $irc->setDebug(variable_get('bot_debugging', 0) ? SMARTIRC_DEBUG_ALL : SMARTIRC_DEBUG_NONE); $irc->setAutoReconnect(TRUE); // reconnect to the server if disconnected. $irc->setAutoRetry(TRUE); // retry if a server connection fails. $irc->setChannelSyncing(TRUE); // keep a list of joined users per channel. $irc->setUseSockets(TRUE); // uses real sockets instead of fsock(). // send every message type the library supports to our wrapper class. // we can automate the creation of these actionhandlers, but not the // class methods below (only PHP 5 supports default methods easily). $irc_message_types = array('UNKNOWN', 'CHANNEL', 'QUERY', 'CTCP', 'NOTICE', 'WHO', 'JOIN', 'INVITE', 'ACTION', 'TOPICCHANGE', 'NICKCHANGE', 'KICK', 'QUIT', 'LOGIN', 'INFO', 'LIST', 'NAME', 'MOTD', 'MODECHANGE', 'PART', 'ERROR', 'BANLIST', 'TOPIC', 'NONRELEVANT', 'WHOIS', 'WHOWAS', 'USERMODE', 'CHANNELMODE', 'CTCP_REQUEST', 'CTCP_REPLY'); foreach ($irc_message_types as $irc_message_type) { $irc->registerActionhandler(constant('SMARTIRC_TYPE_' . $irc_message_type), '.*', $bot, 'invoke_irc_msg_' . strtolower($irc_message_type));
global $doge; try { $doge->sendtoaddress($msg, $amount); } catch (Exception $e) { $irc->message(SMARTIRC_TYPE_CHANNEL, GAMECHANNEL, CTRL_B . $data->nick . CTRL_B . ": An internal error occured trying to send your Dogecoins.. Unfortunately, you win nothing.. :("); $this->game = false; return; } // aaand kill the game finally $this->game = false; $irc->message(SMARTIRC_TYPE_CHANNEL, GAMECHANNEL, CTRL_B . $data->nick . CTRL_B . ": You won " . DOGE . $amount . "!"); file_put_contents("/tmp/moon.info", ""); } } $bot = new monopoly(); $irc = new Net_SmartIRC(); $irc->setDebug(SMARTIRC_DEBUG_NONE); //$irc->setUseSockets(true); $irc->setChannelSyncing(true); $irc->registerActionHandler(SMARTIRC_TYPE_CHANNEL, '/^!taketurn$/', $bot, "takeTurn"); $irc->registerActionHandler(SMARTIRC_TYPE_CHANNEL, '/^!endturn$/', $bot, "endTurn"); $irc->registerActionHandler(SMARTIRC_TYPE_CHANNEL, '/^!payfine$/', $bot, "payFine"); $irc->registerActionHandler(SMARTIRC_TYPE_CHANNEL, '/^!usecard$/', $bot, "useCard"); $irc->registerActionHandler(SMARTIRC_TYPE_CHANNEL, '/^!buy$/', $bot, "buyProperty"); $irc->registerActionHandler(SMARTIRC_TYPE_CHANNEL, '/^!auction$/', $bot, "auctionProperty"); $irc->registerActionHandler(SMARTIRC_TYPE_CHANNEL, '/^!bid\\s/', $bot, "bidProperty"); $irc->registerActionHandler(SMARTIRC_TYPE_CHANNEL, '/^!buildhouse/', $bot, "buildHouse"); $irc->registerActionHandler(SMARTIRC_TYPE_CHANNEL, '/^!sellhouse/', $bot, "sellHouse"); $irc->registerActionHandler(SMARTIRC_TYPE_CHANNEL, '/^!mortgage/', $bot, "mortgageProperty"); $irc->registerActionHandler(SMARTIRC_TYPE_CHANNEL, '/^!unmortgage/', $bot, "unmortgageProperty"); $irc->registerActionHandler(SMARTIRC_TYPE_CHANNEL, '/^!starttrade/', $bot, "startTrade");
$dogetip->move("dogec0in_" . $tipperid, "dogec0in_" . $id, $msg[2]); } catch (Exception $e) { $irc->message(SMARTIRC_TYPE_NOTICE, $data->nick, "An internal error occured. Try again later."); return; } $irc->message(SMARTIRC_TYPE_CHANNEL, $data->channel, CTRL_B . base64_decode("w7jCsA==") . "wow such verification" . base64_decode("wrDDuA==") . CTRL_B . ": " . $data->nick . " -> " . $msg[1] . " " . CTRL_B . base64_decode("w5A=") . $msg[2] . CTRL_B . " [ " . CTRL_B . "/msg wowsuchtips info" . CTRL_B . " ]"); return; } } } } } } } $bot = new wowsuchdoge(); $irc = new Net_SmartIRC(); $irc->setDebug(SMARTIRC_DEBUG_NONE); //$irc->setUseSockets(true); $irc->setChannelSyncing(true); $irc->registerActionHandler(SMARTIRC_TYPE_QUERY, '/^exit\\s/', $bot, "msgExit"); $irc->registerActionHandler(SMARTIRC_TYPE_QUERY, '/^info$/', $bot, "msgInfo"); $irc->registerActionHandler(SMARTIRC_TYPE_QUERY, '/^tipcreate$/', $bot, "msgTipcreate"); $irc->registerActionHandler(SMARTIRC_TYPE_QUERY, '/^withdraw\\s/', $bot, "msgWithdraw"); $irc->registerActionHandler(SMARTIRC_TYPE_QUERY, '/^getvip\\s/', $bot, "msgGetvip"); $irc->registerActionHandler(SMARTIRC_TYPE_QUERY, '/^getad\\s/', $bot, "msgGetad"); $irc->registerActionHandler(SMARTIRC_TYPE_CHANNEL, '/!/', $bot, "chanMsg"); $irc->registerActionHandler(SMARTIRC_TYPE_ACTION, '/!/', $bot, "chanMsg"); $irc->registerActionHandler(SMARTIRC_TYPE_JOIN, '/\\#dogec0in$/', $bot, "onJoin"); $irc->registerActionHandler(SMARTIRC_TYPE_NICKCHANGE, '.*', $bot, "onNickChange"); while (1) { $irc->connect("localhost", 7000, true);
if ($this->lastadmsg == $admsg) { $this->lastadmsg = ""; return; } if (substr($admsg, 0, 16) == ">Global Notice< ") { $admsg = substr($admsg, 16); } // to avoid any exploits by that way ;> $this->lastadmsg = $admsg; $irc->message(SMARTIRC_TYPE_NOTICE, "#dogec0in", $admsg); return; } } date_default_timezone_set("Europe/Berlin"); $bot = new wowsuchdoge(); $irc = new Net_SmartIRC(); $irc->setDebug(0); //$irc->setUseSockets(true); $irc->setChannelSyncing(true); $irc->registerActionHandler(SMARTIRC_TYPE_QUERY, '/^identify\\s/', $bot, "msgIdent"); $irc->registerActionHandler(SMARTIRC_TYPE_QUERY, '/^query(2)?\\s.*/', $bot, "msgQuery"); $irc->registerActionHandler(SMARTIRC_TYPE_QUERY, '/^ad\\s/', $bot, "msgAd"); $irc->registerActionHandler(SMARTIRC_TYPE_QUERY, '/^ban\\s/', $bot, "msgBan"); $irc->registerActionHandler(SMARTIRC_TYPE_QUERY, '/^voice\\s/', $bot, "msgVoice"); $irc->registerActionHandler(SMARTIRC_TYPE_QUERY, '/^exit\\s/', $bot, "msgExit"); $irc->registerActionHandler(SMARTIRC_TYPE_QUERY, '/^global\\s/', $bot, "msgGlobal"); $irc->registerActionHandler(SMARTIRC_TYPE_CHANNEL, '.*', $bot, "timedChanMsg"); $irc->registerActionHandler(SMARTIRC_TYPE_ACTION, '.*', $bot, "timedChanMsg"); $irc->registerActionHandler(SMARTIRC_TYPE_JOIN, '/\\#dogec0in$/', $bot, "onJoin"); $irc->registerActionHandler(SMARTIRC_TYPE_JOIN, '/\\#dogec0in-vip$/', $bot, "onJoinVip"); $irc->registerActionHandler(SMARTIRC_TYPE_PART, '.*', $bot, "onPart");
} } function markOutgoingMessages($id) { $set = array('status' => 1); $query = $this->fpdo->update('irc_outgoing')->set($set)->where('id', $id)->execute(); } public function msgQueue($irc) { // Проверяем исходящие сообщения: $outgoingMessages = $this->fetchOutgoingMessages($this->settings['irc.nickname'], $this->settings['irc.channel']); if ($outgoingMessages) { foreach ($outgoingMessages as $arrayMessages) { // Отправка сообщения в канал: $irc->message(SMARTIRC_TYPE_CHANNEL, $this->settings['irc.channel'], $arrayMessages['message']); $this->markOutgoingMessages($arrayMessages['id']); } } } public function saveMessage($irc, $data) { $this->fpdo->insertInto('irc_incoming', array('date' => $this->date, 'nick' => $data->nick, 'host' => $data->ident . "@" . $data->host, 'channel' => $data->channel, 'message' => $data->message, 'to_user' => $this->settings['irc.nickname']))->execute(); } } $irc = new Net_SmartIRC(array('DebugLevel' => SMARTIRC_DEBUG_ALL, 'ChannelSyncing' => true)); $bot = new MyBot($irc); $irc->connect($bot->settings['irc.server'], $bot->settings['irc.port']); $irc->login($bot->settings['irc.nickname'], 'teh Client olol', 0, 'ololol'); $irc->join(array($bot->settings['irc.channel'])); $irc->listen(); $irc->disconnect();
sleep(1); } } public function _joinChannels(&$irc) { global $channels; foreach ($channels as $prj_id => $options) { foreach ($options as $chan => $categories) { $irc->join($chan); } } } } require_once 'Net/SmartIRC.php'; $bot = new Eventum_Bot(); $irc = new Net_SmartIRC(); $irc->setLogdestination(SMARTIRC_FILE); $irc->setLogfile(APP_IRC_LOG); $irc->setUseSockets(true); $irc->setAutoReconnect(true); $irc->setAutoRetry(true); $irc->setReceiveTimeout(600); $irc->setTransmitTimeout(600); $irc->registerTimehandler(3000, $bot, 'notifyEvents'); // methods that keep track of who is authenticated $irc->registerActionhandler(SMARTIRC_TYPE_QUERY, '^!?list-auth', $bot, 'listAuthenticatedUsers'); $irc->registerActionhandler(SMARTIRC_TYPE_NICKCHANGE, '.*', $bot, '_updateAuthenticatedUser'); $irc->registerActionhandler(SMARTIRC_TYPE_KICK | SMARTIRC_TYPE_QUIT | SMARTIRC_TYPE_PART, '.*', $bot, '_removeAuthenticatedUser'); $irc->registerActionhandler(SMARTIRC_TYPE_LOGIN, '.*', $bot, '_joinChannels'); // real bot commands $irc->registerActionhandler(SMARTIRC_TYPE_QUERY, '^!?help', $bot, 'listAvailableCommands');
/** * Join configured channels. * If channel name contains space, everything after space is considered channel key. * * @param Net_SmartIRC $irc */ private function joinChannels(Net_SmartIRC $irc) { foreach ($this->channels as $prj_id => $options) { foreach ($options as $chan => $categories) { $parts = explode(' ', $chan, 2); if (count($parts) > 1) { // join with key $irc->join($parts[0], $parts[1]); } else { $irc->join($chan); } } } }
protected function encode($text) { return mb_convert_encoding($text, mb_internal_encoding(), IRC_ENCODING); } protected function decode($text) { return mb_convert_encoding($text, IRC_ENCODING, mb_internal_encoding()); } public static function shortenUrl($matches) { $url = $matches[0]; if (defined('BIT_LY_ID') && defined('BIT_LY_API_KEY') && BIT_LY_ID && BIT_LY_API_KEY) { $q = 'version=2.0.1&longUrl=' . urlencode($url) . '&login='******'&apiKey=' . BIT_LY_API_KEY; $ch = curl_init('http://api.bit.ly/shorten?' . $q); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $result = json_decode(curl_exec($ch), true); curl_close($ch); if ('OK' === $result['statusCode']) { return $result['results'][$url]['shortUrl']; } } return $url; } } $irc = new Net_SmartIRC(); $twitter = new Twitter(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET); $bot = new TwitChat($irc, $twitter); $irc->connect(IRC_HOST, IRC_PORT); $irc->login(IRC_NICK, IRC_INFO); $irc->join(array(IRC_CHANNEL)); $irc->listen();
} } } } function help_cmd(&$irc, &$data) { $message = sprintf('For ContriBot Help, see %s', HELP_URL); $irc->message(SMARTIRC_TYPE_CHANNEL, $data->channel, $message); } } /** * Instantiate our bot class and the SmartIRC framework */ $bot = new bot(); $doc_bot = new DocBot(); $irc = new Net_SmartIRC(); /** * Set connection-wide configurations */ $irc->setDebugLevel(SMARTIRC_DEBUG_ALL); // Set debug mode $irc->setUseSockets(true); // We want to use actual sockets, if this is false fsock will be used, which is not as ideal $irc->setChannelSyncing(true); // Channel sync allows us to get user details which we use in our logs, this is how we can check if users are in the channel or not /** * Set up hooks for events to trigger on */ $irc->registerActionHandler(SMARTIRC_TYPE_CHANNEL, '/./', $bot, 'channel_query'); $irc->registerActionHandler(SMARTIRC_TYPE_ACTION, '/./', $bot, 'channel_query'); $irc->registerActionHandler(SMARTIRC_TYPE_KICK, '/(.*)/', $bot, 'log_kick');
/** * (non-PHPdoc) * @see extlibs/Pear/Net/Net_SmartIRC_base#_rawsend($data) */ function _rawsend($data) { // check encoding if (!mb_check_encoding($data, $this->getIrcEncoding())) { $this->log(SMARTIRC_DEBUG_NOTICE, 'WARNIG: Input charactor has worong encoding.', __FILE__, __LINE__); return parent::_rawsend(''); } $data = mb_convert_encoding($data, $this->getIrcEncoding(), 'UTF-8'); return parent::_rawsend($data); }