mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-08 20:28:55 -05:00
More image cog polish
This commit is contained in:
parent
e581230789
commit
f7fa78403d
@ -1,10 +1,6 @@
|
|||||||
import discord
|
import discord
|
||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
from random import randint
|
from random import randint
|
||||||
try:
|
|
||||||
from imgurpython import ImgurClient
|
|
||||||
except:
|
|
||||||
print("imgurpython is not installed. Do 'pip install imgurpython' to use this cog.\n")
|
|
||||||
import aiohttp
|
import aiohttp
|
||||||
import random
|
import random
|
||||||
|
|
||||||
@ -22,7 +18,7 @@ class Image:
|
|||||||
"""Retrieves a random imgur picture
|
"""Retrieves a random imgur picture
|
||||||
|
|
||||||
imgur search [keyword] - Retrieves first hit of search query.
|
imgur search [keyword] - Retrieves first hit of search query.
|
||||||
imgur [subreddit section] [top or new] - retrieves top 3 hottest or latest pictures of today for given a subreddit section, e.g. 'funny'."""
|
imgur [subreddit section] [top or new] - Retrieves top 3 hottest or latest pictures of today for given a subreddit section, e.g. 'funny'."""
|
||||||
imgurclient = ImgurClient("1fd3ef04daf8cab", "f963e574e8e3c17993c933af4f0522e1dc01e230")
|
imgurclient = ImgurClient("1fd3ef04daf8cab", "f963e574e8e3c17993c933af4f0522e1dc01e230")
|
||||||
if text == ():
|
if text == ():
|
||||||
rand = randint(0, 59) #60 results per generated page
|
rand = randint(0, 59) #60 results per generated page
|
||||||
@ -35,6 +31,7 @@ class Image:
|
|||||||
else:
|
else:
|
||||||
await self.bot.say(items[0].link)
|
await self.bot.say(items[0].link)
|
||||||
elif text[0] != ():
|
elif text[0] != ():
|
||||||
|
try:
|
||||||
if text[1] == "top":
|
if text[1] == "top":
|
||||||
imgSort = "top"
|
imgSort = "top"
|
||||||
elif text[1] == "new":
|
elif text[1] == "new":
|
||||||
@ -47,6 +44,8 @@ class Image:
|
|||||||
await self.bot.say("This subreddit section does not exist, try 'funny'")
|
await self.bot.say("This subreddit section does not exist, try 'funny'")
|
||||||
else:
|
else:
|
||||||
await self.bot.say("{} {} {}".format(items[0].link, items[1].link, items[2].link))
|
await self.bot.say("{} {} {}".format(items[0].link, items[1].link, items[2].link))
|
||||||
|
except:
|
||||||
|
await self.bot.say("Type help imgur for details.")
|
||||||
|
|
||||||
@commands.command(no_pm=True)
|
@commands.command(no_pm=True)
|
||||||
async def gif(self, *text):
|
async def gif(self, *text):
|
||||||
@ -98,5 +97,16 @@ class Image:
|
|||||||
else:
|
else:
|
||||||
await self.bot.say("gifr [text]")
|
await self.bot.say("gifr [text]")
|
||||||
|
|
||||||
|
class ModuleNotFound(Exception):
|
||||||
|
def __init__(self, m):
|
||||||
|
self.message = m
|
||||||
|
def __str__(self):
|
||||||
|
return self.message
|
||||||
|
|
||||||
def setup(bot):
|
def setup(bot):
|
||||||
|
global ImgurClient
|
||||||
|
try:
|
||||||
|
from imgurpython import ImgurClient
|
||||||
|
except:
|
||||||
|
raise ModuleNotFound("imgurpython is not installed. Do 'pip install imgurpython' to use this cog.")
|
||||||
bot.add_cog(Image(bot))
|
bot.add_cog(Image(bot))
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user