From dfca8ead8ea1aa22b03ed3b794c7fbf339089a14 Mon Sep 17 00:00:00 2001 From: Reyaansh Jhaveri <68239783+reyaansh0261@users.noreply.github.com> Date: Sat, 17 Apr 2021 09:11:28 +0530 Subject: [PATCH] Create nqn.py --- teapot/cogs/nqn.py | 100 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 teapot/cogs/nqn.py diff --git a/teapot/cogs/nqn.py b/teapot/cogs/nqn.py new file mode 100644 index 0000000..a56408c --- /dev/null +++ b/teapot/cogs/nqn.py @@ -0,0 +1,100 @@ +import discord +from discord import utils +from discord.ext import commands + + +class Emoji(commands.Cog): + def __init__(self, bot): + self.bot = 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 + + @commands.Cog.listener() + async def on_message(self, message): + if message.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))