Skip to content

Commit

Permalink
Añadida funcionalidad para que el bot no te haga ban a ti mismo cuand…
Browse files Browse the repository at this point in the history
…o censuras palabras nuevas. Cambiado algunos detalles menores, mirar comentarios de cada cambio
  • Loading branch information
Daniel-Tomas committed Aug 27, 2020
1 parent ac11a5e commit a04dc8d
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 17 deletions.
8 changes: 3 additions & 5 deletions src/bot.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import discord

This comment has been minimized.

Copy link
@Daniel-Tomas

Daniel-Tomas Aug 27, 2020

Author Contributor

no se usa

from discord.ext import commands
import os

bot = commands.Bot(command_prefix='!')

bot = commands.Bot(command_prefix='¡')

This comment has been minimized.

Copy link
@Daniel-Tomas

Daniel-Tomas Aug 27, 2020

Author Contributor

Un poco raro hacia arriba no?


TOKEN = open('token.txt', 'r').read()

with open('token.txt', 'r') as token_file:
TOKEN = token_file.read()

for file in os.listdir('./funcionalidades'):
if file.endswith('.py'):
Expand Down
45 changes: 33 additions & 12 deletions src/funcionalidades/ban_hammer.py
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):

Expand All @@ -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')
Expand All @@ -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.

Copy link
@Daniel-Tomas

Daniel-Tomas Aug 27, 2020

Author Contributor

el + es para leer tmb, si no me equivoco, y solo estamos escribiendo (appending)

file.write("\n" + word)
self.blacklist.append(word)
await ctx.send('Palabra censurada correctamente :)')
Expand All @@ -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))

0 comments on commit a04dc8d

Please sign in to comment.