-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f5c4f9d
commit b02bcfb
Showing
1 changed file
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import urllib.request | ||
import urllib.error | ||
import json | ||
import plugin | ||
import command | ||
import message | ||
import os | ||
|
||
def onInit(plugin): | ||
#create the basics of our plugin | ||
xkcd_plugin = plugin.plugin.plugin() | ||
xkcd_plugin.plugin = plugin | ||
xkcd_plugin.name = 'star' | ||
|
||
#now to register commands | ||
xkcd_command = command.command() | ||
xkcd_command.plugin = plugin | ||
xkcd_command.name = 'star' | ||
|
||
#add our commands to the plugin | ||
xkcd_plugin.commands = [] #this line is for some reason needed or stuff will break | ||
xkcd_plugin.commands.append(xkcd_command) | ||
|
||
return xkcd_plugin | ||
|
||
def onCommand(message_in): | ||
if message_in.command == 'star': | ||
try: | ||
f = urllib.request.urlopen("https://sydneyerickson.me/starapi/rand.php").read().decode("utf-8") | ||
except urllib.error.URLError as e: | ||
return message.create(body='There was an issue connecting to XKCD'.format(message_in.body)) | ||
|
||
imageName = f.split('/') | ||
if os.path.isfile('cache/star_' + imageName[-1]): | ||
pass | ||
else: | ||
urllib.request.urlretrieve(f, 'cache/star_' + imageName[-1]) | ||
|
||
return message.create(file='cache/star_' + imageName[-1]) |