1
0
Fork 0
ImgurIRCBot/lib/imgurbot.php

49 lines
1.3 KiB
PHP
Raw Permalink Normal View History

2012-11-15 01:34:24 -05:00
<?php
2012-11-15 18:55:19 -05:00
include_once(__DIR__ . '/Net_SmartIRC-1.0.0/SmartIRC.php');
2012-11-15 01:34:24 -05:00
class ImgurBot {
var $imgUrl = 'http://imgur.com';
var $nick;
2012-11-15 19:25:44 -05:00
var $target;
var $host;
2012-11-15 01:34:24 -05:00
function __construct($conf) {
$this->nick = $conf->nick;
$this->target = $conf->target;
2012-11-15 18:55:19 -05:00
$this->host = $conf->host;
2012-11-15 01:34:24 -05:00
}
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);
}
2012-11-15 18:55:19 -05:00
function nickFinder(&$irc, &$data) {
if(preg_match("/^$this->host/", $data->host) == 1) {
2012-11-15 19:25:44 -05:00
if($data->rawmessageex[1] == 'JOIN') {
$this->target = $data->nick;
} else {
$this->target = $data->message;
}
2012-11-15 18:55:19 -05:00
$irc->message(SMARTIRC_TYPE_CHANNEL, $this->target, "You can run but you can't hide!");
}
}
2012-11-15 01:34:24 -05:00
private
function getPageJson($page, $format = 'json') {
$contents = file($this->imgUrl . '/' . $page . '.' . $format);
if($format == 'json') {
return json_decode(implode("\n", $contents));
} else {
return false;
}
}
}