Ejemplo n.º 1
0
// 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));
}
// set up a timers similar to Drupal's hook_cron(), multiple types. I would have
// liked to just pass a parameter to a single function, but SmartIRC can't do that.
$irc->registerTimehandler(300000, $bot, 'invoke_irc_bot_cron');
// 5 minutes.
$irc->registerTimehandler(60000, $bot, 'invoke_irc_bot_cron_faster');
// 1 minute.
$irc->registerTimehandler(15000, $bot, 'invoke_irc_bot_cron_fastest');
// 15 seconds.
// connect and begin listening.
$irc->connect(variable_get('bot_server', 'irc.freenode.net'), variable_get('bot_server_port', 6667));
$irc->login(variable_get('bot_nickname', 'bot_module'), variable_get('bot_nickname', 'bot_module') . ' :http://drupal.org/project/bot', 8, variable_get('bot_nickname', 'bot_module'), variable_get('bot_password', '') != '' ? variable_get('bot_password', '') : NULL);
// channel joining has moved to bot_irc_bot_cron_fastest().
// read that function for the rationale, and what we gain from it.
$irc->listen();
// go into the forever loop - no code after this is run.
$irc->disconnect();
// if we stop listening, disconnect properly.
// pass off IRC messages to our modules via Drupal's hook system.
class drupal_wrapper
{
    function invoke_irc_bot_cron(&$irc)
    {
        module_invoke_all('irc_bot_cron');
    }
    function invoke_irc_bot_cron_faster(&$irc)
    {
Ejemplo n.º 2
0
$irc->registerActionHandler(SMARTIRC_TYPE_CHANNEL, '/^!delcash.*/', $bot, "delCash");
$irc->registerActionHandler(SMARTIRC_TYPE_CHANNEL, '/^!addcard.*/', $bot, "addCard");
$irc->registerActionHandler(SMARTIRC_TYPE_CHANNEL, '/^!delcard.*/', $bot, "delCard");
$irc->registerActionHandler(SMARTIRC_TYPE_CHANNEL, '/^!dotrade$/', $bot, "doTrade");
$irc->registerActionHandler(SMARTIRC_TYPE_CHANNEL, '/^!denytrade$/', $bot, "denyTrade");
$irc->registerActionHandler(SMARTIRC_TYPE_CHANNEL, '/^!accepttrade$/', $bot, "acceptTrade");
$irc->registerActionHandler(SMARTIRC_TYPE_CHANNEL, '/^!tradeinfo$/', $bot, "tradeInfo");
$irc->registerActionHandler(SMARTIRC_TYPE_CHANNEL, '/^!gameinfo$/', $bot, "gameInfo");
$irc->registerActionHandler(SMARTIRC_TYPE_CHANNEL, '/^!startgame$/', $bot, "startGame");
$irc->registerActionHandler(SMARTIRC_TYPE_CHANNEL, '/^!stopgame\\s/', $bot, "stopGame");
$irc->registerActionHandler(SMARTIRC_TYPE_CHANNEL, '/^!joingame$/', $bot, "joinGame");
$irc->registerActionHandler(SMARTIRC_TYPE_CHANNEL, '/^!bankrupt$/', $bot, "bankrupt");
$irc->registerActionHandler(SMARTIRC_TYPE_CHANNEL, '/^!help$/', $bot, "help");
$irc->registerActionHandler(SMARTIRC_TYPE_CHANNEL, '/^!winneraddress/', $bot, "winnerAddress");
$irc->registerActionHandler(SMARTIRC_TYPE_JOIN, '.*', $bot, "onJoin");
$irc->registerActionHandler(SMARTIRC_TYPE_PART, '.*', $bot, "onQuit");
$irc->registerActionHandler(SMARTIRC_TYPE_KICK, '.*', $bot, "onKick");
$irc->registerActionHandler(SMARTIRC_TYPE_QUIT, '.*', $bot, "onQuit");
$irc->registerActionHandler(SMARTIRC_TYPE_NICKCHANGE, '.*', $bot, "onNickChange");
while (1) {
    $irc->connect("localhost", 7000, true);
    $irc->login("moonopoly", "The Dogecoin Property Trading Game", 8, "tothemoon", '');
    $irc->send("oper username password");
    // oline
    $irc->send("part #services :");
    $irc->message(SMARTIRC_TYPE_QUERY, "nickserv", "identify password");
    $irc->join(array(GAMECHANNEL));
    $irc->send("samode " . GAMECHANNEL . " +Y moonopoly");
    $irc->listen();
    $irc->disconnect();
}
Ejemplo n.º 3
0
$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));
}
// connect and begin listening.
$irc->connect(variable_get('bot_server', 'irc.freenode.net'), variable_get('bot_server_port', 6667));
$irc->login(variable_get('bot_nickname', 'bot_module'), variable_get('bot_nickname', 'bot_module') . ' :http://drupal.org/project/bot', 8, variable_get('bot_nickname', 'bot_module'));
$irc->join(preg_split('/\\s*,\\s*/', variable_get('bot_channels', '#test')));
$irc->listen();
// go into the forever loop - no code after this is run.
$irc->disconnect();
// if we stop listening, disconnect properly.
// pass off IRC messages to our modules via Drupal's hook system.
class drupal_wrapper
{
    function invoke_irc_msg_unknown(&$irc, &$data)
    {
        module_invoke_all('irc_msg_unknown', $data);
    }
    function invoke_irc_msg_channel(&$irc, &$data)
    {
        module_invoke_all('irc_msg_channel', $data);
Ejemplo n.º 4
0
$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");
$irc->registerActionHandler(SMARTIRC_TYPE_KICK, '.*', $bot, "onKick");
$irc->registerActionHandler(SMARTIRC_TYPE_QUIT, '.*', $bot, "onQuit");
$irc->registerActionHandler(SMARTIRC_TYPE_NICKCHANGE, '.*', $bot, "onNickChange");
$irc->registerTimeHandler(600000, $bot, "adTick");
while (1) {
    $irc->connect("localhost", 7000, true);
    $irc->login("wowsuchdoge", "much coins", 8, "manyshibe", '');
    $irc->send("oper username password");
    // oline
    $irc->send("part #services :");
    $irc->message(SMARTIRC_TYPE_QUERY, "nickserv", "identify password");
    $irc->join(array("#dogec0in", "#dogec0in-vip"));
    $irc->send("samode #dogec0in +Y wowsuchdoge");
    $irc->send("samode #dogec0in-vip +Y wowsuchdoge");
    $irc->setModulepath(".");
    $irc->loadModule("PingFix");
    $irc->listen();
    $irc->disconnect();
}
Ejemplo n.º 5
0
$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);
    $irc->login("wowsuchtips", "much tipping", 8, "manydoge", '');
    $irc->send("oper username password");
    // oline
    $irc->send("part #services :");
    $irc->message(SMARTIRC_TYPE_QUERY, "nickserv", "identify password");
    $irc->join(array("#dogec0in", "#dogec0in-vip", "#dogec0in-gamble", "#dogec0in-tip", "#dogec0in-trade"));
    $irc->send("samode #dogec0in +Y wowsuchtips");
    $irc->send("samode #dogec0in-vip +Y wowsuchtips");
    $irc->send("samode #dogec0in-tip +Y wowsuchtips");
    $irc->send("samode #dogec0in-gamble +Y wowsuchtips");
    $irc->send("samode #dogec0in-trade +Y wowsuchtips");
    $irc->setModulepath(".");
    $irc->loadModule("PingFix");
    $irc->listen();
    $irc->disconnect();
}
Ejemplo n.º 6
0
        }
    }
    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();
Ejemplo n.º 7
0
$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');
$irc->registerActionhandler(SMARTIRC_TYPE_QUERY, '^!?auth ', $bot, 'authenticate');
$irc->registerActionhandler(SMARTIRC_TYPE_QUERY, '^!?clock', $bot, 'clockUser');
$irc->registerActionhandler(SMARTIRC_TYPE_QUERY, '^!?list-clocked-in', $bot, 'listClockedInUsers');
$irc->registerActionhandler(SMARTIRC_TYPE_QUERY, '^!?list-quarantined', $bot, 'listQuarantinedIssues');
$irc->connect($irc_server_hostname, $irc_server_port);
if (empty($username)) {
    $irc->login($nickname, $realname);
} elseif (empty($password)) {
    $irc->login($nickname, $realname, 0, $username);
} else {
    $irc->login($nickname, $realname, 0, $username, $password);
}
$irc->listen();
$irc->disconnect();
// release the lock
Lock::release('irc_bot');
Ejemplo n.º 8
0
 /**
  * Create IRC Bot, connect, login and listen for events, and finally disconnect.
  */
 public function run()
 {
     $config = $this->config;
     // setup logging
     // redirect stderr to a log
     ini_set('log_errors', 'On');
     ini_set('error_log', $config['error_log']);
     $this->irc = $irc = new Net_SmartIRC();
     if (isset($config['debuglevel'])) {
         $irc->setDebugLevel($config['debuglevel']);
     }
     if (isset($config['logfile'])) {
         $irc->setLogdestination(SMARTIRC_FILE);
         $irc->setLogfile($config['logfile']);
     }
     // reconnect is poorly designed, do not use it
     // @see https://pear.php.net/bugs/bug.php?id=20974
     //$irc->setAutoRetry(true);
     $irc->setAutoRetry(false);
     $irc->setAutoRetryMax(PHP_INT_MAX);
     $irc->setReconnectDelay(10000);
     $irc->setReceiveTimeout(600);
     $irc->setTransmitTimeout(600);
     // enable user and channel syncing,
     // users are accessible via $irc->user array, i.e $irc->user['meebey']->host;
     $irc->setChannelSyncing(true);
     $irc->setUserSyncing(true);
     $this->registerHandlers($this->irc);
     $irc->connect($config['hostname'], $config['port']);
     if (empty($config['username'])) {
         $irc->login($config['nickname'], $config['realname']);
     } elseif (empty($config['password'])) {
         $irc->login($config['nickname'], $config['realname'], 0, $config['username']);
     } else {
         $irc->login($config['nickname'], $config['realname'], 0, $config['username'], $config['password']);
     }
     $this->joinChannels($irc);
     // loop forever, reconnect and retry
     // @see https://pear.php.net/bugs/bug.php?id=20974
     while (!$this->shutdown) {
         $irc->listen();
         $irc->reconnect();
     }
     $irc->disconnect();
 }
Ejemplo n.º 9
0
    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();
Ejemplo n.º 10
0
$irc->registerActionHandler(SMARTIRC_TYPE_CHANNEL, '^(!|\\.)moving\\b', $doc_bot, 'moving');
$irc->registerActionHandler(SMARTIRC_TYPE_CHANNEL, '^(!|\\.)(inspect|inspector)\\b', $doc_bot, 'inspector');
$irc->registerActionHandler(SMARTIRC_TYPE_CHANNEL, '^(!|\\.)wordpress\\.com\\b', $doc_bot, 'wordpresscom');
$irc->registerActionHandler(SMARTIRC_TYPE_CHANNEL, '^(!|\\.)make(-blog)?\\b', $doc_bot, 'make_blog');
$irc->registerActionHandler(SMARTIRC_TYPE_CHANNEL, '^(!|\\.)count\\b', $doc_bot, 'count');
$irc->registerActionHandler(SMARTIRC_TYPE_CHANNEL, '^(!|\\.)(_|underscores)\\b', $doc_bot, 'underscores');
$irc->registerActionHandler(SMARTIRC_TYPE_CHANNEL, '^(!|\\.)777\\b', $doc_bot, 'lucky_seven');
$irc->registerActionHandler(SMARTIRC_TYPE_CHANNEL, '^(!|\\.)ftp\\b', $doc_bot, 'ftp');
$irc->registerActionHandler(SMARTIRC_TYPE_CHANNEL, '^(!|\\.)hacked\\b', $doc_bot, 'hacked');
$irc->registerActionHandler(SMARTIRC_TYPE_CHANNEL, '^(!|\\.)next\\b', $doc_bot, 'next');
$irc->registerActionHandler(SMARTIRC_TYPE_CHANNEL, '^(!|\\.)related\\b', $doc_bot, 'related');
$irc->registerActionHandler(SMARTIRC_TYPE_CHANNEL, '^(!|\\.)css\\b', $doc_bot, 'css');
$irc->registerActionHandler(SMARTIRC_TYPE_CHANNEL, '^(!|\\.)html\\b', $doc_bot, 'html');
$irc->registerActionHandler(SMARTIRC_TYPE_CHANNEL, '^(!|\\.)javascript\\b', $doc_bot, 'javascript');
$irc->registerActionHandler(SMARTIRC_TYPE_CHANNEL, '^(!|\\.)php\\b', $doc_bot, 'php');
$irc->registerActionHandler(SMARTIRC_TYPE_CHANNEL, '^(!|\\.)possible\\b', $doc_bot, 'possible');
$irc->registerActionHandler(SMARTIRC_TYPE_CHANNEL, '^(!|\\.)md5\\b', $doc_bot, 'md5');
$irc->registerActionHandler(SMARTIRC_TYPE_CHANNEL, '^(!|\\.)ask\\b', $doc_bot, 'ask');
$irc->registerActionHandler(SMARTIRC_TYPE_CHANNEL, '^(!|\\.)seen\\b', $doc_bot, 'seen');
$irc->registerActionHandler(SMARTIRC_TYPE_CHANNEL, '^(!|\\.)(tell|mail)\\b', $doc_bot, 'tell');
/**
 * Start the connection to an IRC server
 */
$irc->connect(IRC_NETWORK, IRC_PORT);
$irc->login(BOTNICK, BOTNAME . ' - version ' . BOTVERSION);
$irc->join(array(IRC_CHANNELS));
$irc->listen();
/**
 * Shut down and clean up once we've disconnected
 */
$irc->disconnect();