diff --git a/Teapot.py b/Teapot.py index e747ce5..012da98 100644 --- a/Teapot.py +++ b/Teapot.py @@ -27,12 +27,12 @@ if response[0]['name'] == teapot.version(): print("You are currently running the latest version of Teapot.py!\n") else: - versionlisted = False + version_listed = False for x in response: if x['name'] == teapot.version(): - versionlisted = True + version_listed = True print("You are not using our latest version! :(\n") - if not versionlisted: + if not version_listed: print("You are currently using an unlisted version!\n") elif req.status_code == 404: # 404 Not Found @@ -92,6 +92,7 @@ async def on_ready(): print(f"Connected to DiscordAPI in {round(time.perf_counter() - discord_time_start, 2)}s") time_start = time.perf_counter() + # load cogs teapot.events.__init__(bot) teapot.cogs.cmds.__init__(bot) teapot.cogs.music.setup(bot) @@ -99,6 +100,7 @@ async def on_ready(): teapot.cogs.github.setup(bot) teapot.cogs.cat.setup(bot) teapot.cogs.neko.setup(bot) + teapot.cogs.nqn.setup(bot) if teapot.config.storage_type() == "mysql": for guild in bot.guilds: teapot.managers.database.create_guild_table(guild) diff --git a/teapot/cogs/__init__.py b/teapot/cogs/__init__.py index 7e932c5..719c428 100644 --- a/teapot/cogs/__init__.py +++ b/teapot/cogs/__init__.py @@ -4,3 +4,4 @@ from .music import * from .neko import * from .osu import * +from .nqn import * diff --git a/teapot/cogs/nqn.py b/teapot/cogs/nqn.py new file mode 100644 index 0000000..96caf7b --- /dev/null +++ b/teapot/cogs/nqn.py @@ -0,0 +1,102 @@ +import discord +from discord import utils +from discord.ext import commands + + +class Emoji(commands.Cog): + def __init__(self, bot): + self.bot = bot + self.on_message_send(bot) + + async def getemote(self, arg): + emoji = utils.get(self.bot.emojis, name=arg.strip(":")) + + if emoji is not None: + if emoji.animated: + add = "a" + else: + add = "" + return f"<{add}:{emoji.name}:{emoji.id}>" + else: + return None + + async def getinstr(self, content): + ret = [] + + spc = content.split(" ") + cnt = content.split(":") + + if len(cnt) > 1: + for item in spc: + if item.count(":") > 1: + wr = "" + if item.startswith("<") and item.endswith(">"): + ret.append(item) + else: + cnt = 0 + for i in item: + if cnt == 2: + aaa = wr.replace(" ", "") + ret.append(aaa) + wr = "" + cnt = 0 + + if i != ":": + wr += i + else: + if wr == "" or cnt == 1: + wr += " : " + cnt += 1 + else: + aaa = wr.replace(" ", "") + ret.append(aaa) + wr = ":" + cnt = 1 + + aaa = wr.replace(" ", "") + ret.append(aaa) + else: + ret.append(item) + else: + return content + + return ret + + def on_message_send(self, bot): + @bot.event + async def on_message(message): + if message.author.bot: # check is author bot + return + + if ":" in message.content: + msg = await self.getinstr(message.content) + ret = "" + em = False + smth = message.content.split(":") + if len(smth) > 1: + for word in msg: + if word.startswith(":") and word.endswith(":") and len(word) > 1: + emoji = await self.getemote(word) + if emoji is not None: + em = True + ret += f" {emoji}" + else: + ret += f" {word}" + else: + ret += f" {word}" + + else: + ret += msg + + if em: + webhooks = await message.channel.webhooks() + webhook = utils.get(webhooks, name="Imposter NQN") + if webhook is None: + webhook = await message.channel.create_webhook(name="Imposter NQN") + + await webhook.send(ret, username=message.author.name, avatar_url=message.author.avatar_url) + await message.delete() + + +def setup(bot): + bot.add_cog(Emoji(bot))