Skip to content

Commit 0aaef81

Browse files
committed
Implement NQN emoji feature
Signed-off-by: RedTeaDev <[email protected]>
1 parent 160305c commit 0aaef81

File tree

3 files changed

+100
-95
lines changed

3 files changed

+100
-95
lines changed

Teapot.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@
2727
if response[0]['name'] == teapot.version():
2828
print("You are currently running the latest version of Teapot.py!\n")
2929
else:
30-
versionlisted = False
30+
version_listed = False
3131
for x in response:
3232
if x['name'] == teapot.version():
33-
versionlisted = True
33+
version_listed = True
3434
print("You are not using our latest version! :(\n")
35-
if not versionlisted:
35+
if not version_listed:
3636
print("You are currently using an unlisted version!\n")
3737
elif req.status_code == 404:
3838
# 404 Not Found
@@ -92,13 +92,15 @@
9292
async def on_ready():
9393
print(f"Connected to DiscordAPI in {round(time.perf_counter() - discord_time_start, 2)}s")
9494
time_start = time.perf_counter()
95+
# load cogs
9596
teapot.events.__init__(bot)
9697
teapot.cogs.cmds.__init__(bot)
9798
teapot.cogs.music.setup(bot)
9899
teapot.cogs.osu.setup(bot)
99100
teapot.cogs.github.setup(bot)
100101
teapot.cogs.cat.setup(bot)
101102
teapot.cogs.neko.setup(bot)
103+
teapot.cogs.nqn.setup(bot)
102104
if teapot.config.storage_type() == "mysql":
103105
for guild in bot.guilds:
104106
teapot.managers.database.create_guild_table(guild)

teapot/cogs/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
from .music import *
55
from .neko import *
66
from .osu import *
7+
from .nqn import *

teapot/cogs/nqn.py

Lines changed: 94 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -4,97 +4,99 @@
44

55

66
class Emoji(commands.Cog):
7-
def __init__(self, bot):
8-
self.bot = bot
9-
10-
async def getemote(self, arg):
11-
emoji = utils.get(self.bot.emojis, name = arg.strip(":"))
12-
13-
if emoji is not None:
14-
if emoji.animated:
15-
add = "a"
16-
else:
17-
add = ""
18-
return f"<{add}:{emoji.name}:{emoji.id}>"
19-
else:
20-
return None
21-
22-
async def getinstr(self, content):
23-
ret = []
24-
25-
spc = content.split(" ")
26-
cnt = content.split(":")
27-
28-
if len(cnt) > 1:
29-
for item in spc:
30-
if item.count(":") > 1:
31-
wr = ""
32-
if item.startswith("<") and item.endswith(">"):
33-
ret.append(item)
34-
else:
35-
cnt = 0
36-
for i in item:
37-
if cnt == 2:
38-
aaa = wr.replace(" ", "")
39-
ret.append(aaa)
40-
wr = ""
41-
cnt = 0
42-
43-
if i != ":":
44-
wr += i
45-
else:
46-
if wr == "" or cnt == 1:
47-
wr += " : "
48-
cnt += 1
49-
else:
50-
aaa = wr.replace(" ", "")
51-
ret.append(aaa)
52-
wr = ":"
53-
cnt = 1
54-
55-
aaa = wr.replace(" ", "")
56-
ret.append(aaa)
57-
else:
58-
ret.append(item)
59-
else:
60-
return content
61-
62-
return ret
63-
64-
@commands.Cog.listener()
65-
async def on_message(self, message):
66-
if message.author.bot:
67-
return
68-
69-
if ":" in message.content:
70-
msg = await self.getinstr(message.content)
71-
ret = ""
72-
em = False
73-
smth = message.content.split(":")
74-
if len(smth) > 1:
75-
for word in msg:
76-
if word.startswith(":") and word.endswith(":") and len(word) > 1:
77-
emoji = await self.getemote(word)
78-
if emoji is not None:
79-
em = True
80-
ret += f" {emoji}"
81-
else:
82-
ret += f" {word}"
83-
else:
84-
ret += f" {word}"
85-
86-
else:
87-
ret += msg
88-
89-
90-
if em:
91-
webhooks = await message.channel.webhooks()
92-
webhook = utils.get(webhooks, name = "Imposter NQN")
93-
if webhook is None:
94-
webhook = await message.channel.create_webhook(name = "Imposter NQN")
95-
96-
await webhook.send(ret, username = message.author.name, avatar_url = message.author.avatar_url)
97-
await message.delete()
7+
def __init__(self, bot):
8+
self.bot = bot
9+
self.on_message_send(bot)
10+
11+
async def getemote(self, arg):
12+
emoji = utils.get(self.bot.emojis, name=arg.strip(":"))
13+
14+
if emoji is not None:
15+
if emoji.animated:
16+
add = "a"
17+
else:
18+
add = ""
19+
return f"<{add}:{emoji.name}:{emoji.id}>"
20+
else:
21+
return None
22+
23+
async def getinstr(self, content):
24+
ret = []
25+
26+
spc = content.split(" ")
27+
cnt = content.split(":")
28+
29+
if len(cnt) > 1:
30+
for item in spc:
31+
if item.count(":") > 1:
32+
wr = ""
33+
if item.startswith("<") and item.endswith(">"):
34+
ret.append(item)
35+
else:
36+
cnt = 0
37+
for i in item:
38+
if cnt == 2:
39+
aaa = wr.replace(" ", "")
40+
ret.append(aaa)
41+
wr = ""
42+
cnt = 0
43+
44+
if i != ":":
45+
wr += i
46+
else:
47+
if wr == "" or cnt == 1:
48+
wr += " : "
49+
cnt += 1
50+
else:
51+
aaa = wr.replace(" ", "")
52+
ret.append(aaa)
53+
wr = ":"
54+
cnt = 1
55+
56+
aaa = wr.replace(" ", "")
57+
ret.append(aaa)
58+
else:
59+
ret.append(item)
60+
else:
61+
return content
62+
63+
return ret
64+
65+
def on_message_send(self, bot):
66+
@bot.event
67+
async def on_message(message):
68+
if message.author.bot: # check is author bot
69+
return
70+
71+
if ":" in message.content:
72+
msg = await self.getinstr(message.content)
73+
ret = ""
74+
em = False
75+
smth = message.content.split(":")
76+
if len(smth) > 1:
77+
for word in msg:
78+
if word.startswith(":") and word.endswith(":") and len(word) > 1:
79+
emoji = await self.getemote(word)
80+
if emoji is not None:
81+
em = True
82+
ret += f" {emoji}"
83+
else:
84+
ret += f" {word}"
85+
else:
86+
ret += f" {word}"
87+
88+
else:
89+
ret += msg
90+
91+
if em:
92+
webhooks = await message.channel.webhooks()
93+
webhook = utils.get(webhooks, name="Imposter NQN")
94+
if webhook is None:
95+
webhook = await message.channel.create_webhook(name="Imposter NQN")
96+
97+
await webhook.send(ret, username=message.author.name, avatar_url=message.author.avatar_url)
98+
await message.delete()
99+
98100

99101
def setup(bot):
100-
bot.add_cog(Emoji(bot))
102+
bot.add_cog(Emoji(bot))

0 commit comments

Comments
 (0)