-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
executable file
·41 lines (27 loc) · 944 Bytes
/
main.py
File metadata and controls
executable file
·41 lines (27 loc) · 944 Bytes
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
#!.venv/bin/python
from __future__ import annotations
from os import getenv
import hikari
from dotenv import load_dotenv
from slurs import load_slur_data
load_dotenv()
bot = hikari.GatewayBot(
intents=hikari.Intents.ALL_MESSAGES | hikari.Intents.MESSAGE_CONTENT,
token=getenv("DISCORD_TOKEN", "DISCORD_TOKEN"),
)
SLUR_REGEX = load_slur_data()
@bot.listen()
async def slur_detect(event: hikari.GuildMessageCreateEvent) -> None:
"""Detects usage of slurs in message and keeps track of the slur count."""
if not event.is_human:
return
message_body = event.message.content
if message_body is None:
return
match_result = [{k: v for k, v in m.groupdict().items() if v is not None} for m in SLUR_REGEX.finditer(message_body)]
await event.message.respond(match_result, reply=True)
def main() -> None:
"""Main function for the bot."""
bot.run()
if __name__ == "__main__":
main()