Created
June 3, 2012 22:56
-
-
Save aaronpearce/2865319 to your computer and use it in GitHub Desktop.
iPhotograph Thumber
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* Released by Aaron Pearce (Pickley). All rights reserved. You may use this as you wish, just make sure to mention me. | |
*/ | |
class Random extends extension { | |
public $name = 'Random'; // name - This is the name of the extension! | |
public $version = 1; // version - The version number! You can have this as a string. | |
public $about = 'Meep.'; // about - Brief information about your extension. | |
public $status = true; // status - Whether the extension if on or off as default. true = on, false = off. Default is true. | |
public $author = 'Pickley'; // author - The person who made the extension. Usually you. | |
/// type - This defines the type. This is optional and defaults to the option here, and you can choose from 3 types. | |
public $type = EXT_CUSTOM; | |
protected $times = array(); | |
function init() { | |
/* | |
* Initialise! Here we have the init method! You don't need this but | |
* you should use it to configure commands for the extension and to | |
* hook events to methods. Here I'm only going to show how to hook | |
* a command. | |
*/ | |
$this->addCmd('random', 'c_random'); | |
$this->addCmd('popularPhotos', 'c_popularPhotos'); | |
$this->addCmd('popular', 'c_popular'); | |
$this->addCmd('new', 'c_new'); | |
$this->cmdHelp('random', | |
'Shows random photography thumbs from yours or someone else\'s gallery!<br/><sup>' | |
.$this->Bot->trigger.'random<br/>' | |
); | |
$this->cmdHelp('popular', | |
'Shows most popular photography thumbs rom yours or someone else\'s gallery!<br/><sup>' | |
.$this->Bot->trigger.'popular<br/>' | |
); | |
$this->cmdHelp('popularPhotos', | |
'Shows random photography thumbs from the Popular gallery based on a timeframe. Defaults to all time.<br/><sup>' | |
.$this->Bot->trigger.'popularPhotos<br/>' | |
.$this->Bot->trigger.'popularPhotos [8,24,72,week,month]<br/>' | |
); | |
$this->cmdHelp('new', | |
'Shows the latest photography thumbs from yours or someone else\'s gallery!<br/><sup>' | |
.$this->Bot->trigger.'new<br/>'// Just add a bit of information about the command | |
); | |
} | |
public function timeCheck($from, $ns) { | |
$canPost = false; | |
if($this->times[$from]['lastTime']+300 < time()) { | |
$this->times[$from]['lastTime'] = time(); | |
$canPost = true; | |
} else { | |
$canPost = false; | |
} | |
$privclass = $this->dAmn->chat[$ns]['member'][$from]['pc']; | |
if($privclass == "iModSquad" || $privclass == "iDoNothing") $canPost = true; | |
return $canPost; | |
} | |
function c_random($ns, $from, $message, $target) { | |
$url = "http://backend.deviantart.com/rss.xml?q=gallery%3A%username%+in%3Aphotography&type=deviation"; | |
$arg = args($message, 1); | |
$arg2 = args($message, 2); | |
$privclass = $this->dAmn->chat[$ns]['member'][$from]['pc']; | |
if($arg != "" && ($privclass == "iModSquad" || $privclass == "iDoNothing")) { | |
$user = $arg; | |
} else { | |
$user = $from; | |
} | |
$count = 5; | |
// privclasses | |
switch ($privclass) { | |
case 'iModSquad': | |
$count = 5; | |
break; | |
case 'iPhotographers': | |
$count = 4; | |
break; | |
case 'iRegulars': | |
$count = 5; | |
break; | |
case 'iDontKnow': | |
$count = 0; | |
break; | |
default: | |
break; | |
} | |
if($this->timeCheck($from, $ns)) { | |
if($count == 0) { | |
$msg = $from . ": Sorry, you can't use this until you are in iPhotographers or above!"; | |
} else { | |
$url = str_replace("%username%", $user, $url); | |
$xml = file_get_contents($url); | |
$doc = new DOMDocument(); | |
$doc->loadXML($xml); | |
$xpath = new DOMXpath($doc); | |
$thumbs = array(); | |
$elements = $xpath->query("/rss/channel/item"); | |
foreach ($elements as $element) { | |
$thumb = ":thumb".end(explode("-", $element->getElementsByTagName('link')->item(0)->nodeValue)).":"; | |
$thumbs[] = $thumb; | |
} | |
$rand_thumbs = array_rand($thumbs, $count); | |
$msg = ""; | |
foreach ($rand_thumbs as $rand_thumb) { | |
$msg = $msg . $thumbs[$rand_thumb] . ' '; | |
} | |
} | |
} else { | |
$msg = "Please wait 5 minutes before thumbing again! :thunb167394480:"; | |
} | |
$this->dAmn->say($ns, $msg); | |
} | |
function c_popularPhotos($ns, $from, $message, $target) { | |
$url = "http://backend.deviantart.com/rss.xml?q=boost%3Apopular+in%3Aphotography&type=deviation"; | |
$privclass = $this->dAmn->chat[$ns]['member'][$from]['pc']; | |
$arg = args($message, 1); | |
if($arg != "") { | |
switch ($arg) { | |
case '8': | |
$url = "http://backend.deviantart.com/rss.xml?q=boost%3Apopular+in%3Aphotography+max_age%3A8h&type=deviation"; | |
break; | |
case '24': | |
$url = "http://backend.deviantart.com/rss.xml?q=boost%3Apopular+in%3Aphotography+max_age%3A24h&type=deviation"; | |
break; | |
case '72': | |
$url = "http://backend.deviantart.com/rss.xml?q=boost%3Apopular+in%3Aphotography+max_age%3A72h&type=deviation"; | |
break; | |
case 'week': | |
$url = "http://backend.deviantart.com/rss.xml?q=boost%3Apopular+in%3Aphotography+max_age%3A168h&type=deviation"; | |
break; | |
case 'month': | |
$url = "http://backend.deviantart.com/rss.xml?q=boost%3Apopular+in%3Aphotography+max_age%3A168h&type=deviation"; | |
break; | |
default: | |
break; | |
} | |
} | |
$count = 5; | |
// privclasses | |
switch ($privclass) { | |
case 'iModSquad': | |
$count = 5; | |
break; | |
case 'iPhotographers': | |
$count = 4; | |
break; | |
case 'iRegulars': | |
$count = 5; | |
break; | |
case 'iDontKnow': | |
$count = 0; | |
break; | |
default: | |
break; | |
} | |
if($this->timeCheck($from, $ns)) { | |
if($count == 0) { | |
$msg = $from . ": Sorry, you can't use this until you are in iPhotographers or above!"; | |
} else { | |
$xml = file_get_contents($url); | |
$doc = new DOMDocument(); | |
$doc->loadXML($xml); | |
$xpath = new DOMXpath($doc); | |
$thumbs = array(); | |
$elements = $xpath->query("/rss/channel/item"); | |
foreach ($elements as $element) { | |
$thumb = ":thumb".end(explode("-", $element->getElementsByTagName('link')->item(0)->nodeValue)).":"; | |
$thumbs[] = $thumb; | |
} | |
$rand_thumbs = array_rand($thumbs, $count); | |
foreach ($rand_thumbs as $rand_thumb) { | |
$msg = $msg . $thumbs[$rand_thumb] . ' '; | |
} | |
} | |
} else { | |
$msg = "Please wait 5 minutes before thumbing again! :thunb167394480:"; | |
} | |
$this->dAmn->say($ns, $msg); | |
} | |
function c_popular($ns, $from, $message, $target) { | |
$url = "http://backend.deviantart.com/rss.xml?q=gallery%3A%username%+in%3Aphotography+boost%3Apopular&type=deviation"; | |
$arg = args($message, 1); | |
$arg2 = args($message, 2); | |
$privclass = $this->dAmn->chat[$ns]['member'][$from]['pc']; | |
if($arg != "" && ($privclass == "iModSquad" || $privclass == "iDoNothing")) { | |
$user = $arg; | |
} else { | |
$user = $from; | |
} | |
$count = 5; | |
// privclasses | |
switch ($privclass) { | |
case 'iModSquad': | |
$count = 5; | |
break; | |
case 'iPhotographers': | |
$count = 4; | |
break; | |
case 'iRegulars': | |
$count = 5; | |
break; | |
case 'iDontKnow': | |
$count = 0; | |
break; | |
default: | |
break; | |
} | |
if($this->timeCheck($from, $ns)) { | |
if($count == 0) { | |
$msg = $from . ": Sorry, you can't use this until you are in iPhotographers or above!"; | |
} else { | |
$url = str_replace("%username%", $user, $url); | |
$xml = file_get_contents($url); | |
$doc = new DOMDocument(); | |
$doc->loadXML($xml); | |
$xpath = new DOMXpath($doc); | |
$thumbs = array(); | |
$elements = $xpath->query("/rss/channel/item"); | |
foreach ($elements as $element) { | |
$thumb = ":thumb".end(explode("-", $element->getElementsByTagName('link')->item(0)->nodeValue)).":"; | |
$thumbs[] = $thumb; | |
} | |
$msg = ""; | |
for ($i=0; $i < $count ; $i++) { | |
$msg = $msg . $thumbs[$i] . ' '; | |
} | |
} | |
} else { | |
$msg = "Please wait 5 minutes before thumbing again! :thunb167394480:"; | |
} | |
$this->dAmn->say($ns, $msg); | |
} | |
function c_new($ns, $from, $message, $target) { | |
$url = "http://backend.deviantart.com/rss.xml?q=gallery%3A%username%+in%3Aphotography&type=deviation"; | |
$arg = args($message, 1); | |
$arg2 = args($message, 2); | |
$privclass = $this->dAmn->chat[$ns]['member'][$from]['pc']; | |
if($arg != "" && ($privclass == "iModSquad" || $privclass == "iDoNothing")) { | |
$user = $arg; | |
} else { | |
$user = $from; | |
} | |
$count = 5; | |
// privclasses | |
switch ($privclass) { | |
case 'iModSquad': | |
$count = 5; | |
break; | |
case 'iPhotographers': | |
$count = 4; | |
break; | |
case 'iRegulars': | |
$count = 5; | |
break; | |
case 'iDontKnow': | |
$count = 0; | |
break; | |
default: | |
break; | |
} | |
if($this->timeCheck($from, $ns)) { | |
if($count == 0) { | |
$msg = $from . ": Sorry, you can't use this until you are in iPhotographers or above!"; | |
} else { | |
$url = str_replace("%username%", $user, $url); | |
$xml = file_get_contents($url); | |
$doc = new DOMDocument(); | |
$doc->loadXML($xml); | |
$xpath = new DOMXpath($doc); | |
$thumbs = array(); | |
$elements = $xpath->query("/rss/channel/item"); | |
foreach ($elements as $element) { | |
$thumb = ":thumb".end(explode("-", $element->getElementsByTagName('link')->item(0)->nodeValue)).":"; | |
$thumbs[] = $thumb; | |
} | |
$msg = ""; | |
for ($i=0; $i < $count ; $i++) { | |
$msg = $msg . $thumbs[$i] . ' '; | |
} | |
} | |
} else { | |
$msg = "Please wait 5 minutes before thumbing again! :thunb167394480:"; | |
} | |
$this->dAmn->say($ns, $msg); | |
} | |
} | |
new Random($core); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment