From 4c114aef6e9284f7e27dd76d61f5332d5348efd6 Mon Sep 17 00:00:00 2001 From: flifloo Date: Thu, 5 Nov 2020 14:42:16 +0100 Subject: [PATCH 01/13] Add support of disabled extension for greetings --- extensions/greetings.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/extensions/greetings.py b/extensions/greetings.py index 1c3b0ce..bd169a1 100644 --- a/extensions/greetings.py +++ b/extensions/greetings.py @@ -2,8 +2,10 @@ from discord.ext import commands from discord import Member, Embed, Forbidden from discord.ext.commands import BadArgument +from administrator.check import is_enabled from administrator.logger import logger from administrator import db, config +from administrator.utils import event_is_enabled def check_greetings_message_type(message_type): @@ -23,6 +25,7 @@ class Greetings(commands.Cog): return "Setup join and leave message" @commands.group("greetings", pass_context=True) + @is_enabled() @commands.guild_only() @commands.has_permissions(manage_guild=True) async def greetings(self, ctx: commands.Context): @@ -84,6 +87,8 @@ class Greetings(commands.Cog): @commands.Cog.listener() async def on_member_join(self, member: Member): s = db.Session() + if not event_is_enabled(self.qualified_name, member.guild.id, s): + return m = s.query(db.Greetings).filter(db.Greetings.guild == member.guild.id).first() s.close() if m and m.join_enable: @@ -96,6 +101,8 @@ class Greetings(commands.Cog): @commands.Cog.listener() async def on_member_remove(self, member: Member): s = db.Session() + if not event_is_enabled(self.qualified_name, member.guild.id, s): + return m = s.query(db.Greetings).filter(db.Greetings.guild == member.guild.id).first() s.close() if m and m.leave_enable: From a10ff7daf0989e3de4439016036e244d5b0c00fd Mon Sep 17 00:00:00 2001 From: flifloo Date: Thu, 5 Nov 2020 14:47:11 +0100 Subject: [PATCH 02/13] Add support of disabled extension for invite --- extensions/invite.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/extensions/invite.py b/extensions/invite.py index 85551b2..e569c16 100644 --- a/extensions/invite.py +++ b/extensions/invite.py @@ -6,7 +6,9 @@ from discord.ext import commands from discord.ext.commands import BadArgument import db +from administrator.check import is_enabled from administrator.logger import logger +from administrator.utils import event_is_enabled extension_name = "invite" logger = logger.getChild(extension_name) @@ -24,6 +26,7 @@ class Invite(commands.Cog): return "Get role from a special invite link" @commands.group("invite", pass_context=True) + @is_enabled() @commands.guild_only() @commands.has_guild_permissions(administrator=True) async def invite(self, ctx: commands.Context): @@ -77,6 +80,8 @@ class Invite(commands.Cog): @commands.Cog.listener() async def on_member_join(self, member: Member): + if not event_is_enabled(self.qualified_name, member.guild.id): + return user_invites = await member.guild.invites() for i in self.invites[member.guild.id]: for ui in user_invites: @@ -93,11 +98,15 @@ class Invite(commands.Cog): @commands.Cog.listener() async def on_invite_create(self, invite): + if not event_is_enabled(self.qualified_name, invite.guild.id): + return self.invites[invite.guild.id] = await invite.guild.invites() @commands.Cog.listener() async def on_invite_delete(self, invite): s = db.Session() + if not event_is_enabled(self.qualified_name, invite.guild.id, s): + return invite_role = s.query(db.InviteRole).get({"guild_id": invite.guild.id, "invite_code": invite.code}) if invite_role: s.delete(invite_role) From deffba71e75bdd7402844a4e1c8965170f9b5cd4 Mon Sep 17 00:00:00 2001 From: flifloo Date: Thu, 5 Nov 2020 14:47:58 +0100 Subject: [PATCH 03/13] Add support of disabled extension for pcp --- extensions/pcp.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/extensions/pcp.py b/extensions/pcp.py index 00721a1..0a3df74 100644 --- a/extensions/pcp.py +++ b/extensions/pcp.py @@ -5,6 +5,7 @@ from discord.ext import commands from discord.ext.commands import BadArgument, MissingPermissions import db +from administrator.check import is_enabled from administrator.logger import logger @@ -23,6 +24,7 @@ class PCP(commands.Cog): return "PCP Univ Lyon 1" @commands.group("pcp", pass_context=True) + @is_enabled() @commands.guild_only() async def pcp(self, ctx: commands.Context): group = ctx.message.content.replace(f"{ctx.prefix}{ctx.command} ", "").upper() From 9ad618900a9f606a9d39192461506bdb7a942447 Mon Sep 17 00:00:00 2001 From: flifloo Date: Thu, 5 Nov 2020 14:52:03 +0100 Subject: [PATCH 04/13] Add support of disabled extension for poll --- extensions/poll.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/extensions/poll.py b/extensions/poll.py index d247a9e..e39d617 100644 --- a/extensions/poll.py +++ b/extensions/poll.py @@ -6,8 +6,9 @@ from discord import Embed, RawReactionActionEvent, RawMessageDeleteEvent, RawBul from discord.ext.commands import BadArgument import db +from administrator.check import is_enabled from administrator.logger import logger - +from administrator.utils import event_is_enabled extension_name = "poll" logger = logger.getChild(extension_name) @@ -25,6 +26,7 @@ class Poll(commands.Cog): return "Create poll with a simple command" @commands.group("poll", pass_context=True) + @is_enabled() @commands.guild_only() async def poll(self, ctx: commands.Context, name: str, *choices): if name == "help": @@ -67,9 +69,11 @@ class Poll(commands.Cog): user = await self.bot.fetch_user(payload.user_id) else: user = payload.member - + if not user.bot: s = db.Session() + if payload.guild_id and not event_is_enabled(self.qualified_name, payload.guild_id, s): + return p = s.query(db.Polls).filter(db.Polls.message == payload.message_id).first() if p: message = await self.bot.get_channel(p.channel).fetch_message(p.message) From 2ba73ea5d02172b461e1d2f3e8dd012d68a9cef6 Mon Sep 17 00:00:00 2001 From: flifloo Date: Thu, 5 Nov 2020 14:53:06 +0100 Subject: [PATCH 05/13] Add support of disabled extension for presentation --- extensions/presentation.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/extensions/presentation.py b/extensions/presentation.py index 0f594e1..ffdaee5 100644 --- a/extensions/presentation.py +++ b/extensions/presentation.py @@ -2,9 +2,10 @@ from discord.ext import commands from discord import Embed, Message from discord.ext.commands import BadArgument +from administrator.check import is_enabled from administrator.logger import logger from administrator import db - +from administrator.utils import event_is_enabled extension_name = "presentation" logger = logger.getChild(extension_name) @@ -18,6 +19,7 @@ class Presentation(commands.Cog): return "Give role to user who make a presentation in a dedicated channel" @commands.group("presentation", pass_context=True) + @is_enabled() @commands.guild_only() @commands.has_permissions(manage_guild=True) async def presentation(self, ctx: commands.Context): @@ -63,6 +65,8 @@ class Presentation(commands.Cog): async def on_message(self, message: Message): if message.guild is not None: s = db.Session() + if not event_is_enabled(self.qualified_name, message.guild.id, s): + return p = s.query(db.Presentation).filter(db.Presentation.guild == message.guild.id).first() s.close() if p and p.channel == message.channel.id and p.role not in map(lambda x: x.id, message.author.roles): From 234e8e18774fd0913a2075d6451c4410dee9ba5b Mon Sep 17 00:00:00 2001 From: flifloo Date: Thu, 5 Nov 2020 14:54:00 +0100 Subject: [PATCH 06/13] Add support of disabled extension for purge --- extensions/purge.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/extensions/purge.py b/extensions/purge.py index 38ecc2a..bba7e33 100644 --- a/extensions/purge.py +++ b/extensions/purge.py @@ -3,8 +3,9 @@ from asyncio import sleep from discord.ext import commands from discord import Embed, RawReactionActionEvent +from administrator.check import is_enabled from administrator.logger import logger - +from administrator.utils import event_is_enabled extension_name = "purge" logger = logger.getChild(extension_name) @@ -19,6 +20,7 @@ class Purge(commands.Cog): return "Purge all messages between the command and the next add reaction" @commands.group("purge", pass_context=True) + @is_enabled() @commands.guild_only() @commands.has_permissions(manage_messages=True) async def purge(self, ctx: commands.Context): @@ -45,6 +47,8 @@ class Purge(commands.Cog): @commands.Cog.listener() async def on_raw_reaction_add(self, payload: RawReactionActionEvent): if payload.guild_id: + if not event_is_enabled(self.qualified_name, payload.guild_id): + return user = self.bot.get_user(payload.user_id) message = await self.bot.get_guild(payload.guild_id).get_channel(payload.channel_id)\ .fetch_message(payload.message_id) From b24aebc906a734506766f64ad08f06938ffe2870 Mon Sep 17 00:00:00 2001 From: flifloo Date: Thu, 5 Nov 2020 14:56:18 +0100 Subject: [PATCH 07/13] Add support of disabled extension for reminder --- administrator/check.py | 2 +- extensions/reminder.py | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/administrator/check.py b/administrator/check.py index 3e36548..3d1cb6a 100644 --- a/administrator/check.py +++ b/administrator/check.py @@ -9,7 +9,7 @@ class ExtensionDisabled(commands.CheckFailure): def is_enabled(): async def check(ctx: commands.Context): - if ctx.command.cog: + if ctx.command.cog and ctx.guild: s = db.Session() es = s.query(db.ExtensionState).get((ctx.command.cog.qualified_name, ctx.guild.id)) s.close() diff --git a/extensions/reminder.py b/extensions/reminder.py index 1003f30..bfea5cc 100644 --- a/extensions/reminder.py +++ b/extensions/reminder.py @@ -6,6 +6,7 @@ from discord import Embed from discord.ext.commands import BadArgument from discord.ext import tasks +from administrator.check import is_enabled from administrator.logger import logger from administrator import db from administrator.utils import time_pars, seconds_to_time_string @@ -22,6 +23,7 @@ class Reminders(commands.Cog, name="Reminder"): return "Create and manage reminders" @commands.group("reminder", pass_context=True) + @is_enabled() async def reminder(self, ctx: commands.Context): if ctx.invoked_subcommand is None: await ctx.invoke(self.reminder_help) From 297a05d9f4b717a3e0c1afb84cfbb1e70fb6e250 Mon Sep 17 00:00:00 2001 From: flifloo Date: Thu, 5 Nov 2020 14:59:06 +0100 Subject: [PATCH 08/13] Add support of disabled extension for rorec --- extensions/rorec.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/extensions/rorec.py b/extensions/rorec.py index 4c29431..30f8419 100644 --- a/extensions/rorec.py +++ b/extensions/rorec.py @@ -7,8 +7,9 @@ from discord import Embed, RawReactionActionEvent, RawBulkMessageDeleteEvent, Ra from discord.ext.commands import BadArgument from administrator import db +from administrator.check import is_enabled from administrator.logger import logger - +from administrator.utils import event_is_enabled extension_name = "rorec" logger = logger.getChild(extension_name) @@ -40,6 +41,7 @@ class RoRec(commands.Cog): await (await ctx.channel.fetch_message(ctx.message.id)).remove_reaction(emoji, self.bot.user) @commands.group("rorec", pass_context=True) + @is_enabled() @commands.guild_only() @commands.has_permissions(manage_roles=True) async def rorec(self, ctx: commands.Context): @@ -204,6 +206,8 @@ class RoRec(commands.Cog): @commands.Cog.listener() async def on_raw_reaction_add(self, payload: RawReactionActionEvent): s = db.Session() + if payload.guild_id and not event_is_enabled(self.qualified_name, payload.guild_id, s): + return m = s.query(db.RoRec).filter(db.RoRec.message == payload.message_id).first() s.close() if m and payload.member.id != self.bot.user.id: From 827ec2aadbf1ed758457edb56ac4e9ad62c1fa30 Mon Sep 17 00:00:00 2001 From: flifloo Date: Thu, 5 Nov 2020 15:01:45 +0100 Subject: [PATCH 09/13] Add support of disabled extension for speak --- extensions/speak.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/extensions/speak.py b/extensions/speak.py index 3df870d..df98fa0 100644 --- a/extensions/speak.py +++ b/extensions/speak.py @@ -2,8 +2,9 @@ from discord.ext import commands from discord import Member, VoiceState, Embed, Reaction, Guild from discord.ext.commands import CommandNotFound +from administrator.check import is_enabled from administrator.logger import logger - +from administrator.utils import event_is_enabled extension_name = "speak" logger = logger.getChild(extension_name) @@ -25,6 +26,7 @@ class Speak(commands.Cog): return "Speech manager" @commands.group("speak", pass_context=True) + @is_enabled() @commands.guild_only() @commands.has_guild_permissions(mute_members=True) async def speak(self, ctx: commands.Context): @@ -76,6 +78,8 @@ class Speak(commands.Cog): @commands.Cog.listener() async def on_voice_state_update(self, member: Member, before: VoiceState, after: VoiceState): + if member.guild and not event_is_enabled(self.qualified_name, member.guild.id): + return if self.voice_chan and self.strict and \ (before is None or before.channel is None or before.channel.id != self.voice_chan) and \ (after is not None and after.channel is not None and after.channel.id == self.voice_chan) and \ @@ -92,6 +96,8 @@ class Speak(commands.Cog): @commands.Cog.listener() async def on_reaction_add(self, reaction: Reaction, user: Member): + if user.guild and not event_is_enabled(self.qualified_name, user.guild.id): + return if not user.bot: if self.voice_message and reaction.message.id == self.voice_message.id: if str(reaction.emoji) == "\U0001f5e3": @@ -211,6 +217,8 @@ class Speak(commands.Cog): @commands.Cog.listener() async def on_reaction_remove(self, reaction: Reaction, user: Member): + if user.guild and not event_is_enabled(self.qualified_name, user.guild.id): + return if not user.bot: if self.voice_message and reaction.message.id == self.voice_message.id: if str(reaction.emoji) == "\U0001f5e3" and user.id in self.waiting and user.id != self.last_speaker: From e369b23e96dedeb55ee646553e4c566f50697af4 Mon Sep 17 00:00:00 2001 From: flifloo Date: Thu, 5 Nov 2020 15:02:15 +0100 Subject: [PATCH 10/13] Add support of disabled extension for tex --- extensions/tex.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/extensions/tex.py b/extensions/tex.py index f94620d..93e0fee 100644 --- a/extensions/tex.py +++ b/extensions/tex.py @@ -3,6 +3,7 @@ from urllib.parse import urlencode from discord import Embed from discord.ext import commands +from administrator.check import is_enabled from administrator.logger import logger @@ -18,6 +19,7 @@ class TeX(commands.Cog): return "Render TeX formula" @commands.group("tex", pass_context=True) + @is_enabled() async def tex(self, ctx: commands.Context): if ctx.message.content.count("`") == 2: start = ctx.message.content.find("`") From 04090ccaef1fb065baf52aa7c266175798b40c34 Mon Sep 17 00:00:00 2001 From: flifloo Date: Thu, 5 Nov 2020 15:02:42 +0100 Subject: [PATCH 11/13] Add support of disabled extension for tomuss --- extensions/tomuss.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/extensions/tomuss.py b/extensions/tomuss.py index e52ba7f..1de3739 100644 --- a/extensions/tomuss.py +++ b/extensions/tomuss.py @@ -8,6 +8,7 @@ from discord.ext.commands import BadArgument from feedparser import parse import db +from administrator.check import is_enabled from administrator.logger import logger @@ -25,6 +26,7 @@ class Tomuss(commands.Cog): return "PCP Univ Lyon 1" @commands.group("tomuss", pass_context=True) + @is_enabled() async def tomuss(self, ctx: commands.Context): if ctx.invoked_subcommand is None: await ctx.invoke(self.tomuss_help) From 45f93367a43425c4fa4db96fef6513343cc7280c Mon Sep 17 00:00:00 2001 From: flifloo Date: Thu, 5 Nov 2020 15:03:17 +0100 Subject: [PATCH 12/13] Add support of disabled extension for utils --- extensions/utils.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/extensions/utils.py b/extensions/utils.py index 1a6365b..cfde40d 100644 --- a/extensions/utils.py +++ b/extensions/utils.py @@ -4,6 +4,7 @@ from discord import Embed, Member, Guild from discord.ext import commands from discord.ext.commands import BadArgument +from administrator.check import is_enabled from administrator.logger import logger @@ -19,6 +20,7 @@ class Utils(commands.Cog): return "Some tools" @commands.group("utils", pass_context=True) + @is_enabled() async def utils(self, ctx: commands.Context): if ctx.invoked_subcommand is None: await ctx.invoke(self.utils_help) @@ -50,12 +52,14 @@ class Utils(commands.Cog): await ctx.send(f"```{e.__class__.__name__}: {e}```") @commands.group("ping", pass_context=True) + @is_enabled() async def ping(self, ctx: commands.Context): start = datetime.now() msg = await ctx.send(f"Discord WebSocket latency: `{round(self.bot.latency*1000)}ms`") await msg.edit(content=msg.content+"\n"+f"Bot latency: `{round((msg.created_at - start).microseconds/1000)}ms`") @commands.group("info", pass_context=True) + @is_enabled() async def info(self, ctx: commands.Context): if len(ctx.message.mentions) > 1: raise BadArgument() From 7e9fedd31199121d58a3c8b2d28189485ffca830 Mon Sep 17 00:00:00 2001 From: flifloo Date: Thu, 5 Nov 2020 15:04:27 +0100 Subject: [PATCH 13/13] Add support of disabled extension for warn --- extensions/warn.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/extensions/warn.py b/extensions/warn.py index 17a0ade..ecf3255 100644 --- a/extensions/warn.py +++ b/extensions/warn.py @@ -3,6 +3,7 @@ from discord.ext import commands from discord.ext.commands import BadArgument from administrator import db +from administrator.check import is_enabled from administrator.logger import logger from administrator.utils import time_pars, seconds_to_time_string @@ -39,6 +40,7 @@ class Warn(commands.Cog): return users[user] @commands.group("warn", pass_context=True) + @is_enabled() @commands.guild_only() #@commands.has_permissions(manage_roles=True, kick_members=True, ban_members=True, mute_members=True) async def warn(self, ctx: commands.Context):