Skip to content

Commit 160305c

Browse files
author
RedTea
authored
Merge pull request #38 from senseidevs/patch-2
Create nqn.py
2 parents 7322db4 + dfca8ea commit 160305c

File tree

1 file changed

+100
-0
lines changed

1 file changed

+100
-0
lines changed

teapot/cogs/nqn.py

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
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+
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()
98+
99+
def setup(bot):
100+
bot.add_cog(Emoji(bot))

0 commit comments

Comments
 (0)