-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
69 lines (50 loc) · 1.97 KB
/
main.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
import json
import os
import discord
from discord.ext import commands, tasks
import string
from detections import earrape, speech
valid_chars = string.ascii_letters + string.digits + "äöüß" # Add more if you want
command_path = "commands"
with open("config.json", "r") as fp:
data = json.load(fp)
def cleanup(text: str):
return "".join(char if char in valid_chars else "" for char in text).lower()
class Bot(commands.Bot):
async def on_ready(self):
print(f"{self.user} - Started!")
# Load commands
for file in os.listdir(f"./{command_path}"):
if file.endswith(".py"):
await self.load_extension(f"{command_path}.{file.strip('.py')}")
await self.sync()
async def sync(self):
await bot.tree.sync()
for guild in self.guilds:
bot.tree.copy_global_to(guild=guild)
await bot.tree.sync(guild=guild)
async def on_message(self, message):
if message.author.bot:
return
if not speech.get_audio(message):
return
if earrape.is_earrape():
await message.reply(
embed=discord.Embed(
description=f"**⚠️ Voice-message might contain an earrape!**",
color=discord.Color.yellow()
)
)
recog = speech.to_text()
for badword in data["badwords"]:
if badword.lower() in cleanup(recog.text):
await message.delete()
await message.channel.send(
embed=discord.Embed(
description=f"**Voice-message from {message.author} has been deleted.**\n"
f"**Reason:** Contains profanity",
color=discord.Color.red()
)
)
bot = Bot(command_prefix="!", intents=discord.Intents.all())
bot.run(data["token"])