Compare commits
4 commits
33842a145f
...
13e20f73ad
Author | SHA1 | Date | |
---|---|---|---|
13e20f73ad | |||
04c029b368 | |||
86546dec16 | |||
a2cd241265 |
|
@ -11,6 +11,24 @@ import utils
|
|||
class Images(commands.Cog):
|
||||
"""Commands that post images, or look up images"""
|
||||
|
||||
async def horse_noodle_api(self, ctx, animal):
|
||||
data = await utils.request(f"http://hrsendl.com/api/{animal}")
|
||||
|
||||
try:
|
||||
url = data["data"]["file_url_size_large"]
|
||||
filename = data["data"]["file_name"]
|
||||
except (KeyError, TypeError):
|
||||
return await ctx.send(f"I couldn't connect! Sorry no {animal}s right now ;w;")
|
||||
else:
|
||||
image = await utils.download_image(url)
|
||||
f = discord.File(image, filename=filename)
|
||||
try:
|
||||
await ctx.send(file=f)
|
||||
except discord.HTTPException:
|
||||
await ctx.send(
|
||||
f"File to large to send as attachment, here is the URL: {url}"
|
||||
)
|
||||
|
||||
@commands.command(aliases=['rc'])
|
||||
@utils.can_run(send_messages=True)
|
||||
async def cat(self, ctx):
|
||||
|
@ -66,26 +84,7 @@ class Images(commands.Cog):
|
|||
|
||||
EXAMPLE: !snek
|
||||
RESULT: A beautiful picture of a snek o3o"""
|
||||
data = await utils.request("http://hrsendl.com/api/snake")
|
||||
|
||||
if data is None:
|
||||
await ctx.send("I couldn't connect! Sorry no snakes right now ;w;")
|
||||
return
|
||||
result = data['data']
|
||||
filename = result.get('file_url_size_large', None)
|
||||
if filename is None:
|
||||
await ctx.send("I couldn't connect! Sorry no snakes right now ;w;")
|
||||
return
|
||||
|
||||
image = await utils.download_image(filename)
|
||||
filename = re.search('.*/optimized/large/(.*)', filename).group(1)
|
||||
f = discord.File(image, filename=filename)
|
||||
try:
|
||||
await ctx.send(file=f)
|
||||
except discord.HTTPException:
|
||||
await ctx.send(
|
||||
f"File to large to send as attachment, here is the URL: {url}"
|
||||
)
|
||||
await self.horse_noodle_api(ctx, "snake")
|
||||
|
||||
@commands.command()
|
||||
@utils.can_run(send_messages=True)
|
||||
|
@ -94,26 +93,43 @@ class Images(commands.Cog):
|
|||
|
||||
EXAMPLE: !horse
|
||||
RESULT: A beautiful picture of a horse o3o"""
|
||||
data = await utils.request("http://hrsendl.com/api/horse")
|
||||
await self.horse_noodle_api(ctx, "horse")
|
||||
|
||||
if data is None:
|
||||
await ctx.send("I couldn't connect! Sorry no horses right now ;w;")
|
||||
return
|
||||
result = data['data']
|
||||
filename = result.get('file_url_size_large', None)
|
||||
if filename is None:
|
||||
await ctx.send("I couldn't connect! Sorry no horses right now ;w;")
|
||||
return
|
||||
@commands.command()
|
||||
@utils.can_run(send_messages=True)
|
||||
async def duck(self, ctx):
|
||||
"""Use this to print a random duck image.
|
||||
|
||||
image = await utils.download_image(filename)
|
||||
filename = re.search('.*/optimized/large/(.*)', filename).group(1)
|
||||
f = discord.File(image, filename=filename)
|
||||
try:
|
||||
await ctx.send(file=f)
|
||||
except discord.HTTPException:
|
||||
await ctx.send(
|
||||
f"File to large to send as attachment, here is the URL: {url}"
|
||||
)
|
||||
EXAMPLE: !duck
|
||||
RESULT: A beautiful picture of a duck o3o"""
|
||||
await self.horse_noodle_api(ctx, "duck")
|
||||
|
||||
@commands.command()
|
||||
@utils.can_run(send_messages=True)
|
||||
async def snail(self, ctx):
|
||||
"""Use this to print a random snail image.
|
||||
|
||||
EXAMPLE: !snail
|
||||
RESULT: A beautiful picture of a snail o3o"""
|
||||
await self.horse_noodle_api(ctx, "snail")
|
||||
|
||||
@commands.command()
|
||||
@utils.can_run(send_messages=True)
|
||||
async def pleco(self, ctx):
|
||||
"""Use this to print a random pleco image.
|
||||
|
||||
EXAMPLE: !pleco
|
||||
RESULT: A beautiful picture of a pleco o3o"""
|
||||
await self.horse_noodle_api(ctx, "pleco")
|
||||
|
||||
@commands.command()
|
||||
@utils.can_run(send_messages=True)
|
||||
async def moth(self, ctx):
|
||||
"""Use this to print a random moth image.
|
||||
|
||||
EXAMPLE: !moth
|
||||
RESULT: A beautiful picture of a moth o3o"""
|
||||
await self.horse_noodle_api(ctx, "moth")
|
||||
|
||||
@commands.command()
|
||||
@commands.guild_only()
|
||||
|
|
|
@ -188,11 +188,16 @@ class Owner(commands.Cog):
|
|||
@commands.command()
|
||||
async def bash(self, ctx, *, cmd: str):
|
||||
"""Runs a bash command"""
|
||||
output = subprocess.check_output("{}; exit 0".format(cmd), stderr=subprocess.STDOUT, shell=True)
|
||||
if output:
|
||||
await ctx.send("```\n{}\n```".format(output.decode("utf-8", "ignore").strip()))
|
||||
proc = await asyncio.create_subprocess_shell(
|
||||
cmd,
|
||||
stdout=asyncio.subprocess.PIPE,
|
||||
stderr=asyncio.subprocess.STDOUT
|
||||
)
|
||||
stdout = (await proc.communicate())[0]
|
||||
if stdout:
|
||||
await ctx.send(f'[stdout]\n{stdout.decode()}')
|
||||
else:
|
||||
await ctx.send("No output for `{}`".format(cmd))
|
||||
await ctx.send("Process finished, no output")
|
||||
|
||||
@commands.command()
|
||||
async def shutdown(self, ctx):
|
||||
|
|
Loading…
Reference in a new issue