1
0
Fork 0

Initial Commit

This commit is contained in:
Andrew Tomaka 2012-11-15 01:34:24 -05:00
commit bb417e7c23
4 changed files with 66 additions and 0 deletions

2
.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
conf/*.conf
lib/Net_SmartIRC-1.0.0/*

21
bot.php Normal file
View file

@ -0,0 +1,21 @@
<?php
include_once(__DIR__ . '/lib/imgurbot.php');
$conf = json_decode(implode("\n", file(__DIR__ . '/conf/settings.conf')));
$bot = &new ImgurBot($conf);
$irc = &new Net_SmartIRC();
if($conf->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();

View file

@ -0,0 +1,9 @@
{
"nick": "YourBestFriend",
"server": "irc.chat.com",
"port": 6667,
"target": "TestUser",
"timing": 100,
"ssl": true,
"debug": false
}

34
lib/imgurbot.php Normal file
View file

@ -0,0 +1,34 @@
<?php
include_once(__DIR__ . '/../Net_SmartIRC-1.0.0/SmartIRC.php');
class ImgurBot {
var $imgUrl = 'http://imgur.com';
var $nick;
function __construct($conf) {
$this->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;
}
}
}