-
Notifications
You must be signed in to change notification settings - Fork 0
/
on_message.py
104 lines (86 loc) · 2.15 KB
/
on_message.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
from discord.ext import commands
from discord import utils
import discord
##############################
#nqn 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
# i added extra indent by mistake -_-
@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))