Added command to post xkcd comics

dev
pocketjawa 2017-02-26 21:00:09 -05:00
parent 3d01d00289
commit 86d900dfe9
2 changed files with 30 additions and 1 deletions

View File

@ -8,4 +8,7 @@
**!wtf**: Don't use unless you want a wall of copypasta
**!ups**: Print the status of the main UPS. Updated once a minute.
**!tohru**: Posts a random pic of the one and only Tohru!
**!setplaying**: Sets the bot's Now Playing status to whatever you say (eg !setplaying with Tohru)
**!setplaying**: Sets the bot's Now Playing status to whatever you say (eg !setplaying with Tohru)
**!xkcd**: Posts a random xkcd comic
**!xkcd latest**: Posts the latest xkcd comic
**!xkcd x**: Posts xkcd comic number x (if it exists)

View File

@ -4,6 +4,7 @@ import asyncio
import configparser
import datetime
import random
import xkcd
#Import config file
config = configparser.ConfigParser()
@ -67,6 +68,31 @@ def on_message(message):
elif message.content.lower().startswith('!setplaying'):
yield from client.change_presence(game=discord.Game(name=message.content.partition(' ')[2]))
#xkcd comic fetcher
elif message.content.lower().startswith('!xkcd'):
args = message.content.partition(' ')[2]
if (args is ''):
comic = xkcd.getRandomComic()
comicnum = str (comic.number)
xkmessage = 'xkcd #' + comicnum + ': ' + comic.getTitle() + '\n' + comic.getImageLink() + '\n' + 'Alt Text: '+comic.getAltText()
yield from client.send_message(message.channel, xkmessage)
else:
if ('latest' in args):
comic = xkcd.getLatestComic()
comicnum = str (comic.number)
xkmessage = 'The most recent xkcd is #' + comicnum + ': ' + comic.getTitle() + '\n' + comic.getImageLink() + '\n' + 'Alt Text: '+comic.getAltText()
yield from client.send_message(message.channel, xkmessage)
elif (args.isdigit()):
comic = xkcd.getComic(args)
if (comic.number == -1):
yield from client.send_message(message.channel, 'There is no xkcd comic #' + args + '. Please try again.')
else:
comicnum = str (comic.number)
xkmessage = 'xkcd is #' + comicnum + ': ' + comic.getTitle() + '\n' + comic.getImageLink() + '\n' + 'Alt Text: '+comic.getAltText()
yield from client.send_message(message.channel, xkmessage)
else:
yield from client.send_message(message.channel, '`'+args+'`' + 'is not a valid option. Please leave blank for a random comic, say "latest" for the latest comic or put the number of the comic you want.' )
client.loop.create_task(ups_check())
client.run(token)