mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-07 19:58:54 -05:00
[Image] [p]imgur random: Search terms can now be specified
This commit is contained in:
parent
07c07760c9
commit
cb4c91d86f
@ -28,9 +28,16 @@ class Image:
|
|||||||
await self.bot.send_cmd_help(ctx)
|
await self.bot.send_cmd_help(ctx)
|
||||||
|
|
||||||
@_imgur.command(pass_context=True, name="random")
|
@_imgur.command(pass_context=True, name="random")
|
||||||
async def imgur_random(self, ctx):
|
async def imgur_random(self, ctx, *, term: str=None):
|
||||||
"""Retrieves a random image from Imgur"""
|
"""Retrieves a random image from Imgur
|
||||||
|
|
||||||
|
Search terms can be specified"""
|
||||||
|
if term is None:
|
||||||
task = functools.partial(self.imgur.gallery_random, page=0)
|
task = functools.partial(self.imgur.gallery_random, page=0)
|
||||||
|
else:
|
||||||
|
task = functools.partial(self.imgur.gallery_search, term,
|
||||||
|
advanced=None, sort='time',
|
||||||
|
window='all', page=0)
|
||||||
task = self.bot.loop.run_in_executor(None, task)
|
task = self.bot.loop.run_in_executor(None, task)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -38,9 +45,12 @@ class Image:
|
|||||||
except asyncio.TimeoutError:
|
except asyncio.TimeoutError:
|
||||||
await self.bot.say("Error: request timed out")
|
await self.bot.say("Error: request timed out")
|
||||||
else:
|
else:
|
||||||
|
if results:
|
||||||
item = choice(results)
|
item = choice(results)
|
||||||
link = item.gifv if hasattr(item, "gifv") else item.link
|
link = item.gifv if hasattr(item, "gifv") else item.link
|
||||||
await self.bot.say(link)
|
await self.bot.say(link)
|
||||||
|
else:
|
||||||
|
await self.bot.say("Your search terms gave no results.")
|
||||||
|
|
||||||
@_imgur.command(pass_context=True, name="search")
|
@_imgur.command(pass_context=True, name="search")
|
||||||
async def imgur_search(self, ctx, *, term: str):
|
async def imgur_search(self, ctx, *, term: str):
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user