Skip to content

Commit 82118f5

Browse files
author
RedTea
authored
Merge pull request #56 from RedCokeDevelopment/dev-nqn
Implement NQN emoji feature
2 parents 92650ea + 0aaef81 commit 82118f5

File tree

3 files changed

+108
-3
lines changed

3 files changed

+108
-3
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 Discord API 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: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
import discord
2+
from discord import utils
3+
from discord.ext import commands
4+
5+
6+
class Emoji(commands.Cog):
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+
100+
101+
def setup(bot):
102+
bot.add_cog(Emoji(bot))

0 commit comments

Comments
 (0)