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 1/2] 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)) From 0aaef81c0cd1bc01fa1caf85cb9119b3b0f10477 Mon Sep 17 00:00:00 2001 From: RedTeaDev Date: Fri, 27 Aug 2021 17:31:26 +0800 Subject: [PATCH 2/2] Implement NQN emoji feature Signed-off-by: RedTeaDev --- Teapot.py | 8 +- teapot/cogs/__init__.py | 1 + teapot/cogs/nqn.py | 186 ++++++++++++++++++++-------------------- 3 files changed, 100 insertions(+), 95 deletions(-) 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 index a56408c..96caf7b 100644 --- a/teapot/cogs/nqn.py +++ b/teapot/cogs/nqn.py @@ -4,97 +4,99 @@ 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 __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)) + bot.add_cog(Emoji(bot))