2
2
import json
3
3
import os
4
4
import time
5
+ import discord
5
6
from datetime import datetime
6
7
from functools import partial
7
8
from threading import Thread
8
- import discord
9
+ from profanityfilter import ProfanityFilter
9
10
from bson .json_util import dumps
10
11
from discord .ext import commands
11
12
from dotenv import load_dotenv
@@ -103,15 +104,16 @@ async def on_message(message):
103
104
return await spy_channel .send (content = f"``{ message .author } `` sent me a DM with attachments:\n { links } " )
104
105
105
106
user_profile = UserProfiles (message .author ).getUserProfile ()
106
- server_settings = ServerSettings (message .guild ).getServerDocument ()
107
+ server_settings = ServerSettings (message .guild )
108
+ server_document = server_settings .getServerDocument ()
107
109
if message .content .startswith (PREFIX ):
108
- if not server_settings ["is_banned" ] and not user_profile ["MiscData" ]["is_banned" ]:
110
+ if not server_document ["is_banned" ] and not user_profile ["MiscData" ]["is_banned" ]:
109
111
await bot .process_commands (message )
110
112
else :
111
113
112
114
if message .channel .type == discord .ChannelType .text and message .channel .name .lower ().startswith (
113
115
"count-to-" ):
114
- if server_settings ["modules" ]["counting_channels" ]:
116
+ if server_document ["modules" ]["counting_channels" ]:
115
117
try :
116
118
# try to convert the string to a number
117
119
number = int (message .content )
@@ -128,8 +130,8 @@ async def on_message(message):
128
130
# not a valid number so delete the message
129
131
await message .delete ()
130
132
131
- if server_settings ["modules" ]["message_responses" ]:
132
- custom_message_responses = server_settings ["custom_message_responses" ]
133
+ if server_document ["modules" ]["message_responses" ]:
134
+ custom_message_responses = server_document ["custom_message_responses" ]
133
135
for custom_response in custom_message_responses :
134
136
trigger = custom_response ["trigger" ]
135
137
response = custom_response ["response" ]
@@ -138,14 +140,10 @@ async def on_message(message):
138
140
return
139
141
140
142
# profanity filter
141
- if server_settings ["modules" ]["profanity_filter" ]:
142
- words = json .loads (open ("settings.json" , 'r' ).read ())["profanity_words" ]
143
- if any (substring in message .content .lower () for substring in words ):
144
- await message .delete ()
145
- await asyncio .sleep (1 )
146
- message = await message .channel .send ("A word you said is not allowed in this server! :rage:" )
147
- await asyncio .sleep (5 )
143
+ if server_document ["modules" ]["profanity_filter" ]:
144
+ if server_settings .profanity_filter ().is_profane (message .content ):
148
145
await message .delete ()
146
+ await message .channel .send ("Watch your language! :rage:" , delete_after = 10 )
149
147
150
148
151
149
@app .route ("/api/v1/userCount" , methods = ["GET" ])
@@ -178,10 +176,14 @@ def api_users():
178
176
for user in user_collection .find ():
179
177
user_json = json .loads (dumps (user ))
180
178
x = bot .get_user (user_json ["id" ])
181
- users .append ({"username" : x .name , "id" : x .id , "discriminator" : x .discriminator ,
182
- "avatar_url" : str (x .avatar_url ),
183
- "is_banned" : user_json ["MiscData" ]["is_banned" ],
184
- "is_admin" : user ["id" ] in BotAdmins ().get ()})
179
+ try :
180
+ users .append ({"username" : x .name , "id" : x .id , "discriminator" : x .discriminator ,
181
+ "avatar_url" : str (x .avatar_url ),
182
+ "is_banned" : user_json ["MiscData" ]["is_banned" ],
183
+ "is_admin" : user ["id" ] in BotAdmins ().get ()})
184
+ except AttributeError as e :
185
+ getLogger ().critical (f"[Users API]: User Error - ID: { user ['id' ]} " )
186
+ user_collection .find_one_and_delete ({"id" : user ['id' ]})
185
187
return jsonify (users )
186
188
else :
187
189
return "" , 401
0 commit comments