2020-05-24 01:16:08 +02:00
|
|
|
import logging
|
|
|
|
from io import BytesIO
|
|
|
|
|
|
|
|
import discord
|
|
|
|
from discord.ext import commands, flags
|
|
|
|
|
|
|
|
from app import TuxBot
|
2020-05-27 00:58:53 +02:00
|
|
|
from utils.functions.extra import ContextPlus, command_extra
|
2020-05-24 01:16:08 +02:00
|
|
|
|
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
class Images(commands.Cog, name="Images"):
|
|
|
|
def __init__(self, bot):
|
|
|
|
self.bot = bot
|
|
|
|
self.image_api = "http://0.0.0.0:8080"
|
|
|
|
|
|
|
|
async def _send_meme(self, ctx: ContextPlus, endpoint: str, **passed_flags):
|
|
|
|
async with ctx.typing():
|
|
|
|
url = f"{self.image_api}/{endpoint}?"
|
|
|
|
for key, val in passed_flags.items():
|
|
|
|
if val:
|
|
|
|
url += f"{key}={val}&"
|
|
|
|
|
|
|
|
async with self.bot.session.get(url) as r:
|
|
|
|
if r.status != 200:
|
|
|
|
return await ctx.send("Failed...")
|
|
|
|
|
|
|
|
data = BytesIO(await r.read())
|
|
|
|
|
2020-06-06 18:51:47 +02:00
|
|
|
await ctx.send(file=discord.File(data, "output.png"))
|
2020-05-24 01:16:08 +02:00
|
|
|
|
2020-05-27 00:58:53 +02:00
|
|
|
@command_extra(name="phcomment")
|
2020-05-24 01:16:08 +02:00
|
|
|
@commands.cooldown(1, 5, commands.BucketType.user)
|
2020-06-06 18:51:47 +02:00
|
|
|
async def _phcomment(
|
|
|
|
self,
|
|
|
|
ctx: ContextPlus,
|
|
|
|
user: discord.User = None,
|
|
|
|
*,
|
|
|
|
message: commands.clean_content(
|
|
|
|
fix_channel_mentions=True, escape_markdown=True
|
|
|
|
),
|
|
|
|
):
|
2020-05-24 01:16:08 +02:00
|
|
|
async with ctx.typing():
|
|
|
|
message = message.replace("&", "%26")
|
|
|
|
if user is None:
|
2020-06-06 18:51:47 +02:00
|
|
|
avatar = ctx.author.avatar_url_as(format="png")
|
2020-05-24 01:16:08 +02:00
|
|
|
username = ctx.author.name
|
|
|
|
else:
|
2020-06-06 18:51:47 +02:00
|
|
|
avatar = user.avatar_url_as(format="png")
|
2020-05-24 01:16:08 +02:00
|
|
|
username = user.name
|
|
|
|
|
2020-06-06 18:51:47 +02:00
|
|
|
url = (
|
|
|
|
f"{self.image_api}/ph/comment"
|
|
|
|
f"?image={avatar}"
|
|
|
|
f"&username={username}"
|
|
|
|
f"&message={message}"
|
|
|
|
)
|
2020-05-24 01:16:08 +02:00
|
|
|
|
|
|
|
async with self.bot.session.get(url) as r:
|
|
|
|
if r.status != 200:
|
|
|
|
return await ctx.send("Failed...")
|
|
|
|
|
|
|
|
data = BytesIO(await r.read())
|
|
|
|
|
2020-06-06 18:51:47 +02:00
|
|
|
await ctx.send(file=discord.File(data, "output.png"))
|
2020-05-24 01:16:08 +02:00
|
|
|
|
2020-05-27 00:58:53 +02:00
|
|
|
@command_extra(name="phvideo")
|
2020-05-24 01:16:08 +02:00
|
|
|
@commands.cooldown(1, 5, commands.BucketType.user)
|
2020-06-06 18:51:47 +02:00
|
|
|
async def _phvideo(
|
|
|
|
self,
|
|
|
|
ctx: ContextPlus,
|
|
|
|
image: str,
|
|
|
|
author: discord.User,
|
|
|
|
*,
|
|
|
|
title: commands.clean_content(fix_channel_mentions=True, escape_markdown=True),
|
|
|
|
):
|
2020-05-24 01:16:08 +02:00
|
|
|
async with ctx.typing():
|
2020-06-06 18:51:47 +02:00
|
|
|
url = (
|
|
|
|
f"{self.image_api}/ph/video"
|
|
|
|
f"?image={image}"
|
|
|
|
f"&username={author.name}"
|
|
|
|
f"&title={title}"
|
|
|
|
)
|
2020-05-24 01:16:08 +02:00
|
|
|
|
|
|
|
async with self.bot.session.get(url) as r:
|
|
|
|
if r.status != 200:
|
|
|
|
return await ctx.send("Failed...")
|
|
|
|
|
|
|
|
data = BytesIO(await r.read())
|
|
|
|
|
2020-06-06 18:51:47 +02:00
|
|
|
await ctx.send(file=discord.File(data, "output.png"))
|
2020-05-24 01:16:08 +02:00
|
|
|
|
|
|
|
@flags.add_flag("--text1", type=str)
|
|
|
|
@flags.add_flag("--text2", type=str)
|
|
|
|
@flags.add_flag("--text3", type=str)
|
2020-05-27 00:58:53 +02:00
|
|
|
@command_extra(name="balloon")
|
2020-05-24 01:16:08 +02:00
|
|
|
@commands.cooldown(1, 5, commands.BucketType.user)
|
|
|
|
async def _balloon(self, ctx: ContextPlus, **passed_flags):
|
|
|
|
passed_flags["text3"] = passed_flags.get("text3")
|
|
|
|
passed_flags["text4"] = passed_flags.get("text1")
|
|
|
|
passed_flags["text5"] = passed_flags.get("text2")
|
|
|
|
|
2020-06-06 18:51:47 +02:00
|
|
|
await self._send_meme(ctx, "balloon", **passed_flags)
|
2020-05-24 01:16:08 +02:00
|
|
|
|
|
|
|
@flags.add_flag("--text1", type=str)
|
|
|
|
@flags.add_flag("--text2", type=str)
|
|
|
|
@flags.add_flag("--text3", type=str)
|
2020-05-27 00:58:53 +02:00
|
|
|
@command_extra(name="butterfly")
|
2020-05-24 01:16:08 +02:00
|
|
|
@commands.cooldown(1, 5, commands.BucketType.user)
|
|
|
|
async def _butterfly(self, ctx: ContextPlus, **passed_flags):
|
2020-06-06 18:51:47 +02:00
|
|
|
await self._send_meme(ctx, "butterfly", **passed_flags)
|
2020-05-24 01:16:08 +02:00
|
|
|
|
|
|
|
@flags.add_flag("--text1", type=str)
|
|
|
|
@flags.add_flag("--text2", type=str)
|
2020-05-27 00:58:53 +02:00
|
|
|
@command_extra(name="buttons")
|
2020-05-24 01:16:08 +02:00
|
|
|
@commands.cooldown(1, 5, commands.BucketType.user)
|
|
|
|
async def _buttons(self, ctx: ContextPlus, **passed_flags):
|
2020-06-06 18:51:47 +02:00
|
|
|
await self._send_meme(ctx, "buttons", **passed_flags)
|
2020-05-24 01:16:08 +02:00
|
|
|
|
|
|
|
@flags.add_flag("--text1", type=str)
|
2020-05-27 00:58:53 +02:00
|
|
|
@command_extra(name="cmm")
|
2020-05-24 01:16:08 +02:00
|
|
|
@commands.cooldown(1, 5, commands.BucketType.user)
|
|
|
|
async def _cmm(self, ctx: ContextPlus, **passed_flags):
|
2020-06-06 18:51:47 +02:00
|
|
|
await self._send_meme(ctx, "change_my_mind", **passed_flags)
|
2020-05-24 01:16:08 +02:00
|
|
|
|
|
|
|
@flags.add_flag("--text1", type=str)
|
|
|
|
@flags.add_flag("--text2", type=str)
|
2020-05-27 00:58:53 +02:00
|
|
|
@command_extra(name="drake")
|
2020-05-24 01:16:08 +02:00
|
|
|
@commands.cooldown(1, 5, commands.BucketType.user)
|
|
|
|
async def _drake(self, ctx: ContextPlus, **passed_flags):
|
2020-06-06 18:51:47 +02:00
|
|
|
await self._send_meme(ctx, "drake", **passed_flags)
|
2020-05-24 01:16:08 +02:00
|
|
|
|
|
|
|
@flags.add_flag("--text1", type=str)
|
|
|
|
@flags.add_flag("--text2", type=str, default=False)
|
2020-05-27 00:58:53 +02:00
|
|
|
@command_extra(name="fry")
|
2020-05-24 01:16:08 +02:00
|
|
|
@commands.cooldown(1, 5, commands.BucketType.user)
|
|
|
|
async def _fry(self, ctx: ContextPlus, **passed_flags):
|
2020-06-06 18:51:47 +02:00
|
|
|
await self._send_meme(ctx, "fry", **passed_flags)
|
2020-05-24 01:16:08 +02:00
|
|
|
|
|
|
|
@flags.add_flag("--text1", type=str)
|
|
|
|
@flags.add_flag("--text2", type=str, default=False)
|
2020-05-27 00:58:53 +02:00
|
|
|
@command_extra(name="imagination")
|
2020-05-24 01:16:08 +02:00
|
|
|
@commands.cooldown(1, 5, commands.BucketType.user)
|
|
|
|
async def _imagination(self, ctx: ContextPlus, **passed_flags):
|
2020-06-06 18:51:47 +02:00
|
|
|
await self._send_meme(ctx, "imagination", **passed_flags)
|
2020-05-24 01:16:08 +02:00
|
|
|
|
|
|
|
@flags.add_flag("--text1", type=str)
|
|
|
|
@flags.add_flag("--text2", type=str, default=False)
|
2020-05-27 00:58:53 +02:00
|
|
|
@command_extra(name="everywhere")
|
2020-05-24 01:16:08 +02:00
|
|
|
@commands.cooldown(1, 5, commands.BucketType.user)
|
|
|
|
async def _everywhere(self, ctx: ContextPlus, **passed_flags):
|
2020-06-06 18:51:47 +02:00
|
|
|
await self._send_meme(ctx, "everywhere", **passed_flags)
|
2020-05-24 01:16:08 +02:00
|
|
|
|
|
|
|
@flags.add_flag("--text1", type=str)
|
|
|
|
@flags.add_flag("--text2", type=str)
|
|
|
|
@flags.add_flag("--text3", type=str)
|
2020-05-27 00:58:53 +02:00
|
|
|
@command_extra(name="choice")
|
2020-05-24 01:16:08 +02:00
|
|
|
@commands.cooldown(1, 5, commands.BucketType.user)
|
|
|
|
async def _choice(self, ctx: ContextPlus, **passed_flags):
|
2020-06-06 18:51:47 +02:00
|
|
|
await self._send_meme(ctx, "choice", **passed_flags)
|
2020-05-24 01:16:08 +02:00
|
|
|
|
|
|
|
@flags.add_flag("--text1", type=str)
|
2020-05-27 00:58:53 +02:00
|
|
|
@command_extra(name="pika")
|
2020-05-24 01:16:08 +02:00
|
|
|
@commands.cooldown(1, 5, commands.BucketType.user)
|
|
|
|
async def _pika(self, ctx: ContextPlus, **passed_flags):
|
2020-06-06 18:51:47 +02:00
|
|
|
await self._send_meme(ctx, "pika", **passed_flags)
|
2020-05-24 01:16:08 +02:00
|
|
|
|
|
|
|
@flags.add_flag("--text1", type=str)
|
|
|
|
@flags.add_flag("--text2", type=str)
|
|
|
|
@flags.add_flag("--text3", type=str)
|
2020-05-27 00:58:53 +02:00
|
|
|
@command_extra(name="pkp")
|
2020-05-24 01:16:08 +02:00
|
|
|
@commands.cooldown(1, 5, commands.BucketType.user)
|
|
|
|
async def _pkp(self, ctx: ContextPlus, **passed_flags):
|
2020-06-06 18:51:47 +02:00
|
|
|
await self._send_meme(ctx, "pkp", **passed_flags)
|
2020-05-24 01:16:08 +02:00
|
|
|
|
|
|
|
@flags.add_flag("--text1", type=str)
|
|
|
|
@flags.add_flag("--text2", type=str)
|
2020-05-27 00:58:53 +02:00
|
|
|
@command_extra(name="puppet")
|
2020-05-24 01:16:08 +02:00
|
|
|
@commands.cooldown(1, 5, commands.BucketType.user)
|
|
|
|
async def _puppet(self, ctx: ContextPlus, **passed_flags):
|
2020-06-06 18:51:47 +02:00
|
|
|
await self._send_meme(ctx, "puppet", **passed_flags)
|
2020-05-24 01:16:08 +02:00
|
|
|
|
|
|
|
@flags.add_flag("--text1", type=str)
|
2020-06-06 18:51:47 +02:00
|
|
|
@command_extra(name="scroll_of_truth", alias=["sot"])
|
2020-05-24 01:16:08 +02:00
|
|
|
@commands.cooldown(1, 5, commands.BucketType.user)
|
|
|
|
async def _sot(self, ctx: ContextPlus, **passed_flags):
|
2020-06-06 18:51:47 +02:00
|
|
|
await self._send_meme(ctx, "scroll_of_truth", **passed_flags)
|