1
1
from __future__ import annotations
2
2
3
3
import asyncio
4
- from typing import Final
4
+ from typing import Final , cast
5
5
6
6
import nextcord
7
7
from nextcord .ext import commands
@@ -14,6 +14,12 @@ class Oneword(commands.Cog):
14
14
def __init__ (self , bot : commands .Bot ) -> None :
15
15
self ._bot : commands .Bot = bot
16
16
17
+ async def check_if_sending_consecutive_messages (
18
+ self , channel : nextcord .TextChannel
19
+ ):
20
+ messages : list [nextcord .Message ] = await channel .history (limit = 2 ).flatten ()
21
+ return messages [1 ].author == messages [0 ].author
22
+
17
23
@commands .Cog .listener ()
18
24
async def on_message (self , message : nextcord .Message ) -> None :
19
25
if message .author .bot :
@@ -22,13 +28,28 @@ async def on_message(self, message: nextcord.Message) -> None:
22
28
return # type: ignore[reportAttributeAccessIssue]
23
29
if message .channel .id != ONEWORD_CHANNEL_ID :
24
30
return
25
- if " " in message .content :
31
+ ONEWORD_CHANNEL = cast ( # noqa: F841
32
+ nextcord .TextChannel , self ._bot .get_channel (ONEWORD_CHANNEL_ID )
33
+ )
34
+
35
+ # r = await self.check_if_sending_consecutive_messages(ONEWORD_CHANNEL)
36
+ if " " in message .content or "\n " in message .content :
26
37
await message .delete ()
27
- r = await message .channel .send (
28
- "Message which have space(s) are not allowed."
38
+ s = await message .channel .send (
39
+ "Message which have space(s) or newlines are not allowed."
29
40
)
30
41
await asyncio .sleep (5 )
31
- await r .delete ()
42
+ await s .delete ()
43
+ return
44
+
45
+ # if r:
46
+ # await message.delete()
47
+ # s = await message.channel.send("Nice try, kid.")
48
+ # await asyncio.sleep(5)
49
+ # await s.delete()
50
+ # return
51
+
52
+ return
32
53
33
54
@commands .Cog .listener ()
34
55
async def on_message_edit (
@@ -48,6 +69,18 @@ async def on_message_edit(
48
69
49
70
@commands .Cog .listener ()
50
71
async def on_message_delete (self , message : nextcord .Message ) -> None :
72
+ # audit_log = await message.guild.audit_logs(limit=1).flatten()
73
+ # audit_log_entry: nextcord.AuditLogEntry = audit_log[0]
74
+ # try:
75
+ # assert audit_log_entry.action == nextcord.AuditLogAction.message_delete
76
+ # except AssertionError:
77
+ # return
78
+ # if (
79
+ # (audit_log_entry.action == nextcord.AuditLogAction.message_delete)
80
+ # and (audit_log_entry.user == message.guild.me)
81
+ # and (audit_log_entry.extra.channel.id == ONEWORD_CHANNEL_ID) # type: ignore
82
+ # ):
83
+ # return
51
84
if message .author .bot :
52
85
return
53
86
if " " in message .content :
0 commit comments