|
4 | 4 |
|
5 | 5 |
|
6 | 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() |
| 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 | + |
98 | 100 |
|
99 | 101 | def setup(bot): |
100 | | - bot.add_cog(Emoji(bot)) |
| 102 | + bot.add_cog(Emoji(bot)) |
0 commit comments