commit bb417e7c23ac264e701d17816b37d42c036730ee Author: Andrew Tomaka Date: Thu Nov 15 01:34:24 2012 -0500 Initial Commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c25fb08 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +conf/*.conf +lib/Net_SmartIRC-1.0.0/* diff --git a/bot.php b/bot.php new file mode 100644 index 0000000..5adb7a4 --- /dev/null +++ b/bot.php @@ -0,0 +1,21 @@ +debug) $irc->setDebug(SMARTIRC_DEBUG_ALL); +$irc->registerTimehandler(10000, $bot, 'randomTop'); +if($conf->ssl) { + $irc->setUseSockets(FALSE); + $irc->connect('ssl://' . $conf->server, $conf->port); +} else { + $irc->setUseSockets(TRUE); + $irc->connect($conf->server, $conf->port); +} + +$irc->login($conf->nick, 'ImgurBot', 0, $conf->nick); +$irc->listen(); +$irc->disconnect(); diff --git a/conf/settings.conf.sample b/conf/settings.conf.sample new file mode 100644 index 0000000..4b4232c --- /dev/null +++ b/conf/settings.conf.sample @@ -0,0 +1,9 @@ +{ + "nick": "YourBestFriend", + "server": "irc.chat.com", + "port": 6667, + "target": "TestUser", + "timing": 100, + "ssl": true, + "debug": false +} \ No newline at end of file diff --git a/lib/imgurbot.php b/lib/imgurbot.php new file mode 100644 index 0000000..233decd --- /dev/null +++ b/lib/imgurbot.php @@ -0,0 +1,34 @@ +nick = $conf->nick; + $this->target = $conf->target; + } + + function quit(&$irc, &$data) { + if($data->nick == $nick) $irc->disconnect(); + } + + function randomTop(&$irc, $format = 'json') { + $images = $this->getPageJson('/gallery/top/all', $format); + $random = $images->data[rand(0, count($images->data) - 1)]; + + $irc->message(SMARTIRC_TYPE_CHANNEL, $this->target, $this->imgUrl . '/gallery/' . $random->hash); + } + + private + function getPageJson($page, $format = 'json') { + $contents = file($this->imgUrl . '/' . $page . '.' . $format); + if($format == 'json') { + return json_decode(implode("\n", $contents)); + } else { + return false; + } + } +} \ No newline at end of file