This repository has been archived by the owner on Mar 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
240 lines (127 loc) · 8.1 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
import disnake #import the discord fork. I'm using Disnake for this project since it's an easy fork.
from disnake.ext import commands #import commands from Disnake.
from disnake.ext.commands import Param #import the parameter from Disnake.
import os #import the Operating system. Needed for restarts.
import sys #import the system. Needed for restarts.
from disnake.ext import * #import the ability to add bad words. Needed for commands.
intents = disnake.Intents.default() #Imports to get the bot working.
bot = commands.Bot(command_prefix="+", intents=intents) #define prefix and define intents
@bot.event
async def on_ready():
print("Bot is starting and ready for use!..") #when the bot's ready to be used, print a message to the console.
#-------------------custom------------------------#
with open("badwords.txt", encoding="utf8") as file: #open a file called `badwords.txt`
blacklist = file.read().split('\n') #let the bot read the list as "blacklist" and split the content
@bot.command() #define command and the decorator
@commands.has_permissions(administrator=True) #tell what permission can add a bad word
async def add(ctx, *, word): #pass context and define the word to add.
with open("badwords.txt", "a") as f: #open the bad words file as a file.
if word in blacklist: #check to see if a word that a user tried to add is in the filter already.
return await ctx.send("That word is already blacklisted!") #if word in filter already, return and send..
else: #check to see if the word is NOT in `blacklist`
f.write("\n"+word) #indent line and write the word.
f.close() #close the text file.
await ctx.send(f'`{word}` \n had been added to blacklist. Please allow up to 5 seconds while the system restarts.') #write to the author that the word has been added.
os.execl(sys.executable, sys.executable, *sys.argv) #restart the bot so the bot can sync the data.
@bot.command()
@commands.has_permissions(administrator=True)
async def clear_custom_filter(ctx):
file = open("badwords.txt","r+") #read the file
file.truncate(0) #delete all contents in file
file.close() #close the file
with open("badwords.txt", "a") as f:
f.write("eiufewhiuwefhuwefhwfhueiwfehihewfiwefiuwefiuhwefiuh") #write nonsense to the file. If file is empty the bot will delete everything sent on Discord.
f.close()
await ctx.send(f'Bad word list cleared. Please allow up to 5 seconds while the system restarts.') #tell the author that the bad word list has been cleared.
os.execl(sys.executable, sys.executable, *sys.argv)
@bot.command()
@commands.has_permissions(administrator=True)
async def view_custom_filter(ctx): #view the custom filter of bad words
await ctx.send(f'View the bad word list here ```{blacklist}```.') #send the bad word list
#simple filter
@bot.listen() #listen events will listen for messages on Discord.
async def on_message(message):
message.content = message.content.lower() #check to see if message is in caps or not.
message.content = disnake.utils.remove_markdown(message.content) #remove markdown. Exampples: `||test||` " ```test``` "
if message.content == "eiufewhiuwefhuwefhwfhueiwfehihewfiwefiuwefiuhwefiuh":
return
else:
for word in blacklist: #get each bad word
if message.author.bot == True: #check to see if author is a bot. if you want the bot to detect bad words on another bot, remove this line
return #return the function of seeing if author is a bot. if you want the bot to detect bad words on another bot, remove this line
if message.content.count(word) > 0: #check the content count once.
await message.delete() #delete the bad word
embed = disnake.Embed(title="Message Deleted", description= f"Bad word blocked by {message.author.mention}..", colour=disnake.Color.random()) #send an embed
await message.channel.send(embed=embed) #send embed to channel
#uncomment the lines underneeth if you want the bot to send a webhook of the user swearing.
# channel_webhooks = await message.channel.webhooks()
# webhook_count = 0
#
# for webhook in channel_webhooks:
#
# if webhook.user.id == message.author.id and webhook.name == "Bot Webhook":
# await webhook.send(
# content=message.content, username=message.author.display_name, avatar_url=message.author.avatar
# )
# return
#
# new_webhook = await message.channel.create_webhook(name="Bot Webhook", reason="Bot Webhook")
# await new_webhook.send(content=message.content, username=message.author.display_name, avatar_url=message.author.avatar)
#-------------------base-filter------------------------#
with open("basefilter.txt", encoding="utf8") as file:
blacklist2 = file.read().split('\n')
@bot.command()
@commands.has_permissions(administrator=True)
async def clear_base_filter(ctx):
file = open("basefilter.txt","r+")
file.truncate(0)
file.close()
with open("basefilter.txt", "a") as f:
f.write("eiufewhiuwefhuwefhwfhueiwfehihewfiwefiuwefiuhwefiuihfeihufewiuhefwihuqfihuqfiheuihuqwdihbh") #checks to see if the default word is in blacklist.
f.close()
await ctx.send(f'Base filter list cleared. Please allow up to 5 seconds while the system restarts.')
os.execl(sys.executable, sys.executable, *sys.argv)
@bot.command()
@commands.has_permissions(administrator=True)
async def view_base_filter(ctx):
await ctx.send(f'View the base filter here ```{blacklist2}```.')
@bot.command()
@commands.has_permissions(administrator=True)
async def restore_base_filter(ctx):
os.remove("basefilter.txt") #remove the file so all contents get deleted
f= open("basefilter.txt","w+") #add the same file again
print("File created!") #print the file has been made
f.write("nigga\nnigger") #write default bad words
f.close()
await ctx.send(f'The base filter has been restored! had been added to blacklist. Please allow up to 5 seconds while the system restarts.')
os.execl(sys.executable, sys.executable, *sys.argv)
@bot.listen()
async def on_message(message):
message.content = message.content.lower()
message.content = disnake.utils.remove_markdown(message.content)
if message.content == "eiufewhiuwefhuwefhwfhueiwfehihewfiwefiuwefiuhwefiuihfeihufewiuhefwihuqfihuqfiheuihuqwdihbh": #checks to see if the default word is in blacklist.
return
else:
for word in blacklist2:
if message.author.bot == True:
return
if message.content.count(word) > 0:
await message.delete()
embed = disnake.Embed(title="Message Deleted", description= f"Bad word blocked by {message.author.mention}..", colour=disnake.Color.random())
embed.timestamp = disnake.utils.utcnow()
await message.channel.send(embed=embed)
#uncomment the lines underneeth if you want the bot to send a webhook of the user swearing.
# channel_webhooks = await message.channel.webhooks()
# webhook_count = 0
#
# for webhook in channel_webhooks:
#
# if webhook.user.id == message.author.id and webhook.name == "Bot Webhook":
# await webhook.send(
# content=message.content, username=message.author.display_name, avatar_url=message.author.avatar
# )
# return
#
# new_webhook = await message.channel.create_webhook(name="Bot Webhook", reason="Bot Webhook")
# await new_webhook.send(content=message.content, username=message.author.display_name, avatar_url=message.author.avatar)
bot.run("BOT_TOKEN") #insert the bot token