-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.py
72 lines (65 loc) · 3.49 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
70
71
72
import discord
import os
from better_profanity import profanity
from supabase import create_client, Client
from dotenv import load_dotenv
load_dotenv()
url: str = os.environ.get("SUPABASE_URL")
key: str = os.environ.get("SUPABASE_KEY")
supabase: Client = create_client(url, key)
bot = discord.Client()
class MyClient(discord.Client):
async def on_ready(self):
print('Logged in as')
print(self.user.name)
print(self.user.id)
print('------')
async def on_message(self, message):
# we do not want the bot to reply to itself
if message.author.id == self.user.id:
return
if profanity.contains_profanity(message.content) and message.channel.name == "bot-tests":
author_banable = True
print(message.author.roles)
for x in message.author.roles:
if x.name == "Developer":
author_banable = False
if x.name == "Moderator":
author_banable = False
if x.name == "Admin":
author_banable = False
if x.name == "🖥 Team NativeBase":
author_banable = False
if x.name == "Community Executive":
author_banable = False
print(author_banable)
await message.channel.send("No profanity please! {} You would be banned if you say that.".format(message.author.mention))
await message.delete()
culprit_details = supabase.table('profanity_bot_ban_list').select(
"profanity_strikes, profanity_contents").eq("discord_auth_id", message.author.id).execute()
# assert len(culprit_details.get("data", [])) > 0
print(culprit_details)
if len(culprit_details[0]) > 0:
profanity_strikes = culprit_details[0][0]["profanity_strikes"]
profanity_contents = culprit_details[0][0]["profanity_contents"]
profanity_strikes += 1
if profanity_strikes <= 100:
supabase.table('profanity_bot_ban_list').update({"profanity_strikes": profanity_strikes, "profanity_contents": "{},{}".format(profanity_contents, message.content)}).eq(
"discord_auth_id", message.author.id).execute()
elif profanity_strikes > 100: # keeping 100 for now as a safety measure
if(author_banable):
await message.author.ban()
await message.channel.send("{} has been banned for using profanity!".format(message.author.mention))
supabase.table('profanity_bot_ban_list').update({"profanity_strikes": profanity_strikes, "profanity_contents": "{},{}".format(profanity_contents, message.content)}).eq(
"discord_auth_id", message.author.id).execute()
else:
supabase.table("profanity_bot_ban_list").insert(
{"discord_auth_id": message.author.id, "user_name": message.author.name, "profanity_strikes": 1, "profanity_contents": message.content}).execute()
# assert data.get("status_code") in (200, 201)
# await message.reply(message.content, mention_author=True)
if message.content.startswith('!reset profanity'):
await message.delete()
supabase.table('profanity_bot_ban_list').delete().execute()
await message.channel.send("Profanity strikes reset!")
client = MyClient()
client.run(os.environ.get("DISCORD_TOKEN"))