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