-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Añadida funcionalidad para que el bot no te haga ban a ti mismo cuand…
…o censuras palabras nuevas. Cambiado algunos detalles menores, mirar comentarios de cada cambio
- Loading branch information
1 parent
ac11a5e
commit a04dc8d
Showing
2 changed files
with
36 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,18 @@ | ||
import discord | ||
from discord.ext import commands | ||
|
||
PERMITTED_ROLES_NAMES = ('Junta', 'Admin') | ||
|
||
|
||
def setup(bot): | ||
bot.add_cog(BanHammer(bot)) | ||
|
||
|
||
def have_permitted_rol(autor_roles): | ||
for autor_rol in autor_roles: | ||
if autor_rol.name in PERMITTED_ROLES_NAMES: | ||
return True | ||
return False | ||
|
||
|
||
class BanHammer(commands.Cog): | ||
|
||
|
@@ -20,14 +32,27 @@ async def on_message(self, message): | |
if message.author == self.bot.user: | ||
return | ||
|
||
message_content = message.content | ||
forbidden_words_used = [ | ||
i for i in self.blacklist if message.content.casefold().count(i) > 0] | ||
i for i in self.blacklist if message_content.casefold().count(i) > 0] | ||
|
||
if(len(forbidden_words_used) > 0): | ||
await message.delete() # Delete the message | ||
# Send a message on the same channel | ||
await message.channel.send(message.author.mention + ", debes cuidar tu vocabulario, jovencito") | ||
await message.author.send("El mensaje \n" + str(""f"```css\n{message.content}```""") + "no se ajusta a las normas, en los próximos mensajes no uses: " + str(forbidden_words_used).strip('[]')) # Send a private message to the user | ||
if len(forbidden_words_used) > 0: | ||
censor_command = self.bot.get_command('censor') | ||
censor_command_names = censor_command.aliases | ||
censor_command_names.append(censor_command.name) | ||
str_ = message_content.split()[0] | ||
# If one with permitted roles is baning a word, we dont ban his message | ||
if have_permitted_rol(message.author.roles) and str_[0] == self.bot.command_prefix \ | ||
and str_[1:] in censor_command_names: | ||
pass | ||
else: | ||
await message.delete() # Delete the message | ||
# Send a message on the same channel | ||
await message.channel.send(message.author.mention + ", debes cuidar tu vocabulario, jovencito") | ||
# Send a private message to the user | ||
await message.author.send("El mensaje \n" + str(f'```diff\n-"{message_content}"```') + | ||
"no se ajusta a las normas, en los próximos mensajes no uses: " + | ||
str(forbidden_words_used).strip('[]')) | ||
|
||
@commands.command(name='censor') | ||
@commands.has_role('Junta') | ||
|
@@ -36,7 +61,7 @@ async def ban_word(self, ctx): | |
if word in self.blacklist: | ||
await ctx.send("La palabra ya estaba baneada") | ||
else: | ||
with open("blacklist_insultos.txt", "a+") as file: | ||
with open("blacklist_insultos.txt", "a") as file: | ||
This comment has been minimized.
Sorry, something went wrong.
Daniel-Tomas
Author
Contributor
|
||
file.write("\n" + word) | ||
self.blacklist.append(word) | ||
await ctx.send('Palabra censurada correctamente :)') | ||
|
@@ -59,7 +84,3 @@ async def unban_word(self, ctx): | |
async def on_command_error(self, ctx, error): | ||
if isinstance(error, commands.errors.CheckFailure): | ||
await ctx.send('Lo siento, no es nada personal, pero no tienes permiso para hacer eso :)') | ||
|
||
|
||
def setup(bot): | ||
bot.add_cog(BanHammer(bot)) |
no se usa