60 lines
2.0 KiB
Python
Executable File
60 lines
2.0 KiB
Python
Executable File
import discord
|
|
from discord.ext import commands
|
|
|
|
from data import constants
|
|
from functions import checks, bannedWords
|
|
|
|
|
|
class Events(commands.Cog):
|
|
def __init__(self, client):
|
|
self.client = client
|
|
|
|
@commands.Cog.listener()
|
|
async def on_connect(self):
|
|
print("Connected")
|
|
|
|
@commands.Cog.listener()
|
|
async def on_ready(self):
|
|
print("Ready")
|
|
self.client.banned_words = bannedWords.load()
|
|
|
|
@commands.Cog.listener()
|
|
async def on_message(self, message):
|
|
if message.guild is None:
|
|
return
|
|
|
|
# The bot sends a confirmation message after banning a word,
|
|
# allow the bot to send this message.
|
|
# This also makes it possible for the bot to send an embed
|
|
# with that message in #ModLogs.
|
|
#
|
|
# Allow mods to use these words as well to whitelist them.
|
|
if message.author.id == constants.wcbID or checks.isModPlus(message):
|
|
return
|
|
|
|
# Check for banned words
|
|
for word in self.client.banned_words:
|
|
if word in message.content.lower():
|
|
await message.delete()
|
|
return await self.bannedWordEmbed(message, word)
|
|
|
|
async def bannedWordEmbed(self, message, word):
|
|
modLogs = message.guild.get_channel(constants.ModLogs)
|
|
|
|
embed = discord.Embed(colour=discord.Colour.red())
|
|
|
|
iconFile = discord.File("files/images/server_icon.png", "icon.png")
|
|
embed.set_author(name="Bad Word Usage", icon_url="attachment://icon.png")
|
|
|
|
embed.add_field(name="Author", value="{} #{}".format(message.author.display_name, message.author.discriminator))
|
|
embed.add_field(name="Channel", value=message.channel.mention)
|
|
embed.add_field(name="Word", value=word)
|
|
embed.add_field(name="Zin", value=message.content, inline=False)
|
|
embed.set_footer(text=embed.timestamp)
|
|
|
|
await modLogs.send(embed=embed, file=iconFile)
|
|
|
|
|
|
def setup(client):
|
|
client.add_cog(Events(client))
|