import discord import logging import aiohttp import asyncio import io import threading from pathlib import Path import glob from discord.ext import commands logger = logging.getLogger(__name__) class LoveEmote(): def __init__(self, name, path): self.name = name self.path = path class LoveEmoteCog(commands.Cog): def __init__(self, bot: commands.Bot): self.emotes = list() async def cog_load(self): PROJ_DIR = Path(__file__).resolve().parent.parent emotes = [] types = ["*.webp", "*.gif"] for t in types: emotes = glob.glob(f"{PROJ_DIR}/emotes/{t}") for e in emotes: p = Path(e) self.emotes.append(LoveEmote(p.stem, p)) logger.debug(self.emotes) logger.debug(f"{PROJ_DIR}/{t}") # self.emotes = emotes @commands.command(name="emote_list", aliases=['el'], description="get list of gif emotes") async def emote_list(self, ctx: commands.Context): """[emote_list | el] List emotes available to the bot""" data = "\n".join([f" - {e.name}" for e in self.emotes]) await ctx.send(data) @commands.command(name="emote_send", aliases=["e"], description="Send an emote to the channel") async def send_emote(self, ctx: commands.Context, emote_name: str): """[emote_send | e] Send an emote to the channel""" for e in self.emotes: if e.name == emote_name: with open(e.path, 'rb') as f: await ctx.message.delete() data = io.BytesIO(f.read()) file_data = discord.File(data, filename=f"{e.name}.{e.path.suffix}") await ctx.send(f"{ctx.author.display_name} sent {e.name}", file=file_data) return await ctx.send("Emote not found, contact aram to create one") async def setup(bot: commands.Bot) -> None: """Register the voice_gen cog with the bot.""" await bot.add_cog(LoveEmoteCog(bot))