Created
June 3, 2012 22:34
-
-
Save aaronpearce/2865248 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 under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 License, which allows you to copy, distribute, transmit, alter, transform, | |
* and build upon this work but not use it for commercial purposes, providing that you attribute me, photofroggy ([email protected]) for its creation. | |
* | |
* | |
* Here we have an example of a Contra extension! | |
* Every extension is a class, and the class has to be | |
* an extension of the extension class, or it won't work | |
* properly. | |
*/ | |
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; | |
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('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 random photography thumbs from the Popular gallery based on a timeframe. Defaults to all time.<br/><sup>' | |
.$this->Bot->trigger.'popular<br/>' | |
.$this->Bot->trigger.'popular[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.'newest<br/>'// Just add a bit of information about the command | |
); | |
} | |
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($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] . ' '; | |
} | |
} | |
$this->dAmn->say($ns, $msg); | |
} | |
function c_popular($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($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] . ' '; | |
} | |
} | |
$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($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] . ' '; | |
} | |
} | |
echo $msg; | |
$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