Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from discord.ext import commands

import cogs.fancyEmbeds as fEmbeds
import functions
from utils import utils

# Logging config
logging.basicConfig(format='[%(asctime)s] %(levelname)s: %(message)s', level=logging.INFO)
Expand Down Expand Up @@ -158,7 +158,7 @@ async def send_cog_help(self,cog):
filters = cursor.execute("SELECT * FROM message_filter").fetchall()
filter_tuple = namedtuple("filter_tuple", ["enabled", "wildcard", "exact"])
for guild_filter in filters:
functions.update_filter(bot, guild_filter)
utils.update_filter(bot, guild_filter)

#load prefixes into bot var
bot.guild_prefixes = {}
Expand Down
32 changes: 17 additions & 15 deletions cogs/automod.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
from discord.ext import commands

import cogs.fancyEmbeds as fEmbeds
import functions
from utils import utils
from utils import checks
from utils.sql import sql


async def word_filter_pre_invoke(self,ctx):
Expand Down Expand Up @@ -40,7 +42,7 @@ def __init__(self, bot):
self.connection = bot.connection

@commands.group(aliases=["word_filter"], brief=":abcd: ")
@commands.check(functions.has_modrole)
@commands.check(checks.has_modrole)
@commands.before_invoke(word_filter_pre_invoke)
async def wordFilter(self,ctx):
"""Modifies the server message word filter."""
Expand Down Expand Up @@ -80,7 +82,7 @@ async def wordFilter_set_wild(self,ctx,*,new_filter=None):
await ctx.send("Filter set.")
async with self.connection.execute("SELECT * from message_filter WHERE guild=?",(ctx.guild.id,)) as cursor:
current_filter = await cursor.fetchone()
functions.update_filter(self.bot, current_filter)
utils.update_filter(self.bot, current_filter)

@wordFilter_set.command(name="exact", brief=":ballpoint_pen: ")
async def wordFilter_set_exact(self,ctx,*,new_filter=None):
Expand All @@ -92,7 +94,7 @@ async def wordFilter_set_exact(self,ctx,*,new_filter=None):
cursor = await self.connection.execute("SELECT * from message_filter WHERE guild=?",(ctx.guild.id,)).fetchone()
current_filter = await cursor.fetchone()
await cursor.close()
functions.update_filter(self.bot, current_filter)
utils.update_filter(self.bot, current_filter)

@wordFilter.command(name="add", brief=":pencil: ")
async def wordFilter_add(self,ctx,*words):
Expand Down Expand Up @@ -130,7 +132,7 @@ async def wordFilter_add(self,ctx,*words):
current_filter = await cursor.execute("SELECT * from message_filter WHERE guild=?",(ctx.guild.id,))
current_filter = await current_filter.fetchone()
await cursor.close()
functions.update_filter(self.bot, current_filter)
utils.update_filter(self.bot, current_filter)
await ctx.send("Added to filter.")

@wordFilter.command(name="remove",aliases=["del","delete"], brief=":x: ")
Expand Down Expand Up @@ -171,7 +173,7 @@ async def wordFilter_remove(self,ctx,*words):
current_filter = await cursor.execute("SELECT * from message_filter WHERE guild=?",(ctx.guild.id,))
current_filter = await current_filter.fetchone()
await cursor.close()
functions.update_filter(self.bot, current_filter)
utils.update_filter(self.bot, current_filter)
await ctx.send(f"Removed from filter. {'The following words were not found so not removed: ' if notFoundWords else ''}{' '.join(notFoundWords) if notFoundWords else ''}")

@wordFilter.command(name="get",aliases=["list"], brief=":notepad_spiral: ")
Expand Down Expand Up @@ -202,11 +204,11 @@ async def wordFilter_toggle(self,ctx):
current_filter = await cursor.execute("SELECT * from message_filter WHERE guild=?",(ctx.guild.id,))
current_filter = await current_filter.fetchone()
await cursor.close()
functions.update_filter(self.bot, current_filter)
utils.update_filter(self.bot, current_filter)
await ctx.send(f"Filter now {'enabled' if enabled == 1 else 'disabled'}.")

@commands.group(name="spamFilter",aliases=["spam_filter"], brief=":loudspeaker: ")
@commands.check(functions.has_modrole)
@commands.check(checks.has_modrole)
@commands.before_invoke(spam_filter_pre_invoke)
async def spamFilter(self,ctx):
"""Set various filters to help reduce spam!"""
Expand Down Expand Up @@ -292,7 +294,7 @@ async def spamFilter_repeatingLimit(self,ctx,limit:int=None):
await ctx.send(f"Character repeat limit now {limit if limit > -1 else 'disabled'}.")

@commands.group(aliases=["name_filter"], brief=":name_badge: ")
@commands.check(functions.has_modrole)
@commands.check(checks.has_modrole)
async def nameFilter(self,ctx):
"""Modifies the name filter."""
if ctx.invoked_subcommand is None:
Expand Down Expand Up @@ -329,7 +331,7 @@ async def nameFilter_setnames(self, ctx):

#used to make sure custom nickname follows guild filter (preventing an infinite loop) and doesn't exceed character limit
def valid_nick(nick):
if functions.filter_check(self.bot, nick, ctx.guild.id):
if checks.filter_check(self.bot, nick, ctx.guild.id):
return "failed filter"
elif len(nick) > 32:
return "too long"
Expand Down Expand Up @@ -390,7 +392,7 @@ async def check_message(self,message):
return
if isinstance(message.channel, discord.channel.DMChannel):
return
if functions.has_modrole(message, self.bot) or functions.has_adminrole(message, self.bot):
if checks.has_modrole(message, self.bot) or checks.has_adminrole(message, self.bot):
return
if message.guild.id not in self.bot.guild_filters:
return
Expand Down Expand Up @@ -556,7 +558,7 @@ async def on_member_join(self, member):
#checks if username is appropriate
if not await SqlCommands.namefilter_enabled(member.guild.id):
return
if functions.filter_check(self.bot, member.display_name, member.guild.id):
if checks.filter_check(self.bot, member.display_name, member.guild.id):
try:
new_name = await SqlCommands.get_new_nick(member.guild.id, "username")
await member.edit(nick=new_name)
Expand Down Expand Up @@ -639,7 +641,7 @@ async def on_member_update(self, before, after):
#Checks if member has an appropriate nick when they update it
if not await SqlCommands.namefilter_enabled(after.guild.id):
return
if functions.filter_check(self.bot, after.display_name, after.guild.id):
if checks.filter_check(self.bot, after.display_name, after.guild.id):
try:
new_name = await SqlCommands.get_new_nick(after.guild.id, "nickname")
await after.edit(nick=new_name)
Expand Down Expand Up @@ -673,7 +675,7 @@ async def on_user_update(self, before, after):
member = guild.get_member(after.id)
if not await SqlCommands.namefilter_enabled(guild.id):
continue
if not member.nick and functions.filter_check(self.bot, member.display_name, member.guild.id):
if not member.nick and checks.filter_check(self.bot, member.display_name, member.guild.id):
try:
new_name = await SqlCommands.get_new_nick(after.guild.id, "username")
await after.edit(nick=new_name)
Expand Down Expand Up @@ -701,4 +703,4 @@ async def on_user_update(self, before, after):
def setup(bot):
global SqlCommands
bot.add_cog(AutoMod(bot))
SqlCommands = functions.Sql(bot)
SqlCommands = sql.sql(bot)
4 changes: 2 additions & 2 deletions cogs/community.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
from discord.ext import commands, tasks
from PIL import Image

import functions
import cogs.fancyEmbeds as fEmbeds
from utils import checks


class Community(commands.Cog):
Expand Down Expand Up @@ -64,7 +64,7 @@ async def get_worm(self,id,colour=False):
return discord.File(arr,filename="worm.png"),wormColour

@commands.group(brief=":ballot_box: ")
@commands.check(functions.has_modrole)
@commands.check(checks.has_modrole)
async def poll(self, ctx):
"""Create polls!"""
if ctx.invoked_subcommand is None:
Expand Down
4 changes: 2 additions & 2 deletions cogs/fancyEmbeds.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import discord
from discord.ext import commands

import functions
from utils import checks

#Add cog to the bot
def setup(bot):
Expand Down Expand Up @@ -149,7 +149,7 @@ def addFooter(self, embed, footer, bot):

#Embed command group
@commands.group(help="Manage how embeds are sent.", brief=":page_facing_up: ")
@commands.check(functions.has_modrole)
@commands.check(checks.has_modrole)
async def embed(self, ctx):
if ctx.invoked_subcommand is None:
await ctx.send_help(ctx.command)
Expand Down
46 changes: 24 additions & 22 deletions cogs/moderation.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
from discord.ext import commands, tasks

import cogs.fancyEmbeds as fEmbeds
import functions
from utils.time import timeconverters, InSeconds
from utils import checks
from utils.sql import sql


class Moderation(commands.Cog):
Expand All @@ -21,7 +23,7 @@ def __init__(self, bot):
self.connection = bot.connection

@commands.group(help="Purge command.", brief=":x: ")
@commands.check(functions.has_modrole)
@commands.check(checks.has_modrole)
async def purge(self,ctx):
if ctx.invoked_subcommand is None:
await ctx.send_help(ctx.command)
Expand All @@ -42,7 +44,7 @@ def filter_check(message):

#ban
@commands.command(help="bans a user", brief=":hammer: ")
@commands.check(functions.has_modrole)
@commands.check(checks.has_modrole)
async def ban(self, ctx, member : discord.Member, *, reason=None):
if not ctx.guild.me.guild_permissions.ban_members:
await ctx.send("I don't have permissions to ban people.")
Expand Down Expand Up @@ -97,7 +99,7 @@ async def ban(self, ctx, member : discord.Member, *, reason=None):
await channel.send(embed=embed)

@commands.command(help="kicks a user", brief=":boot: ")
@commands.check(functions.has_modrole)
@commands.check(checks.has_modrole)
async def kick(self, ctx, member : discord.Member, *, reason=None):
if not ctx.guild.me.guild_permissions.kick_members:
await ctx.send("I don't have permissions to kick people.")
Expand Down Expand Up @@ -153,7 +155,7 @@ async def kick(self, ctx, member : discord.Member, *, reason=None):

#unban
@commands.command(help="unbans a user", brief=":key: ")
@commands.check(functions.has_modrole)
@commands.check(checks.has_modrole)
async def unban(self, ctx, user : discord.User):
unbanTime = time.time()

Expand Down Expand Up @@ -196,8 +198,8 @@ async def unban(self, ctx, user : discord.User):

#gravel
@commands.command(help="Gravels a user", brief=":mute: ")
@commands.check(functions.has_modrole)
async def gravel(self, ctx, member : discord.Member, graveltime: functions.InSeconds, *, reason=None):
@commands.check(checks.has_modrole)
async def gravel(self, ctx, member : discord.Member, graveltime: InSeconds, *, reason=None):
if reason is None:
reason = "No reason specified"
roleid = await SqlCommands.get_role(ctx.guild.id, "gravel")
Expand Down Expand Up @@ -248,8 +250,8 @@ async def gravel(self, ctx, member : discord.Member, graveltime: functions.InSec
await channel.send(embed=embed)

@commands.command(help="Mutes a user", brief=":mute: ")
@commands.check(functions.has_modrole)
async def mute(self, ctx, member : discord.Member, mutetime: functions.InSeconds, *, reason=None):
@commands.check(checks.has_modrole)
async def mute(self, ctx, member : discord.Member, mutetime: InSeconds, *, reason=None):
now = time.time()
if reason is None:
reason = "No reason specified"
Expand Down Expand Up @@ -302,7 +304,7 @@ async def mute(self, ctx, member : discord.Member, mutetime: functions.InSeconds
await channel.send(embed=embed)

@commands.command(help="warns a user", brief=":warning: ")
@commands.check(functions.has_modrole)
@commands.check(checks.has_modrole)
async def warn(self, ctx, member : discord.Member, *, reason):

style = fEmbeds.fancyEmbeds.getActiveStyle(self, ctx.guild.id)
Expand Down Expand Up @@ -341,7 +343,7 @@ async def warn(self, ctx, member : discord.Member, *, reason):
await channel.send(embed=embed)

@commands.command(help="Shows a user's modlogs", brief=":file_folder: ")
@commands.check(functions.has_modrole)
@commands.check(checks.has_modrole)
async def modlogs(self, ctx, member : discord.User):

style = fEmbeds.fancyEmbeds.getActiveStyle(self, ctx.guild.id)
Expand Down Expand Up @@ -373,7 +375,7 @@ async def modlogs(self, ctx, member : discord.User):
await ctx.send(embed = logEmbed)

@commands.command(help="Shows information on a case", brief=":notepad_spiral: ")
@commands.check(functions.has_modrole)
@commands.check(checks.has_modrole)
async def case(self, ctx, case:int):
cursor = await self.connection.execute("SELECT id_in_guild, guild, user, type, reason, started, expires, moderator FROM caselog WHERE id = ?", (case,))
caseinfo = await cursor.fetchone()
Expand Down Expand Up @@ -407,7 +409,7 @@ async def case(self, ctx, case:int):
await ctx.send(embed = logEmbed)

@commands.command(help="Unmutes a User", brief=":sound: ")
@commands.check(functions.has_modrole)
@commands.check(checks.has_modrole)
async def unmute(self, ctx, member : discord.Member):
mod = str(ctx.author)
unmutetime = time.time()
Expand Down Expand Up @@ -444,7 +446,7 @@ async def unmute(self, ctx, member : discord.Member):
await channel.send(embed=embed)

@commands.command(help="Ungravels a User", brief=":sound: ")
@commands.check(functions.has_modrole)
@commands.check(checks.has_modrole)
async def ungravel(self, ctx, member : discord.Member):
mod = str(ctx.author)
ungraveltime = time.time()
Expand Down Expand Up @@ -533,9 +535,9 @@ async def memberinfo(self, ctx, member: discord.Member):
else:
rolefieldname = f"Roles - {len(mentionedroles)}"

if functions.has_modrole_no_ctx(member, self.bot):
if checks.has_modrole_no_ctx(member, self.bot):
ack = ack + "Server Moderator, "
if functions.has_adminrole_no_ctx(member, self.bot):
if checks.has_adminrole_no_ctx(member, self.bot):
ack = ack + "Server Administrator, "
if member == member.guild.owner:
ack = ack + "Server Owner, "
Expand Down Expand Up @@ -741,7 +743,7 @@ async def serverinfo(self, ctx):
await ctx.send(embed=embed)

@commands.command(brief=":card_box: ")
@commands.check(functions.has_modrole)
@commands.check(checks.has_modrole)
async def moderations(self, ctx):
"""Shows all active moderations in the current guild."""

Expand Down Expand Up @@ -775,7 +777,7 @@ async def moderations(self, ctx):
await ctx.send(embed=modEmbed)

@commands.command(brief=":mute: ", help="Server mutes a user, preventing them from talking in VC", aliases=["servermute", "voicemute"])
@commands.check(functions.has_modrole)
@commands.check(checks.has_modrole)
async def server_mute(self, ctx, member: discord.Member):
if member.voice == None:
await ctx.send("This user isn't currently in a voice channel!")
Expand All @@ -787,7 +789,7 @@ async def server_mute(self, ctx, member: discord.Member):
await ctx.send(f"Sounds good! I server muted {member.name}")

@commands.command(brief=":speaker: ", help="Unmutes a user that is server muted", aliases=["serverunmute", "voiceunmute", "unmutevoice"])
@commands.check(functions.has_modrole)
@commands.check(checks.has_modrole)
async def server_unmute(self, ctx, member: discord.Member):
if member.voice == None:
await ctx.send("This user isn't currently in a voice channel!")
Expand Down Expand Up @@ -844,7 +846,7 @@ async def bot_check_once(self,ctx):
self.bot.cooldowns[ctx.guild.id] = {}
if ctx.guild.id not in self.bot.pending_cooldowns.keys():
self.bot.pending_cooldowns[ctx.guild.id] = {}
if functions.has_modrole(ctx) or functions.has_adminrole(ctx):
if checks.has_modrole(ctx) or checks.has_adminrole(ctx):
return True
now = datetime.datetime.now()
if now < self.bot.cooldowns[ctx.guild.id].get(ctx.author.id,now):
Expand Down Expand Up @@ -875,9 +877,9 @@ async def before_invoke(self,ctx): # There is no way to put a global check behin
self.bot.cooldowns[ctx.guild.id][cooldown[0][0]] = cooldown[0][1]

SqlCommands = None
TimeConversions = functions.timeconverters()
TimeConversions = timeconverters()

def setup(bot):
global SqlCommands
SqlCommands = functions.Sql(bot)
SqlCommands = sql.sql(bot)
bot.add_cog(Moderation(bot))
Loading