From 14f2ab7e3f88eddf9d53132dfaf9858fde9275e3 Mon Sep 17 00:00:00 2001 From: flifloo Date: Thu, 23 Jul 2020 21:32:43 +0200 Subject: [PATCH] Fix private messages --- extensions/help.py | 7 ++++--- extensions/presentation.py | 11 ++++++----- extensions/purge.py | 23 ++++++++++++----------- 3 files changed, 22 insertions(+), 19 deletions(-) diff --git a/extensions/help.py b/extensions/help.py index f2e38bb..8be14e3 100644 --- a/extensions/help.py +++ b/extensions/help.py @@ -1,6 +1,7 @@ from discord import Embed from discord.ext import commands -from discord.ext.commands import CommandNotFound, MissingRequiredArgument, BadArgument, MissingPermissions +from discord.ext.commands import CommandNotFound, MissingRequiredArgument, BadArgument, MissingPermissions, \ + NoPrivateMessage from administrator import config from administrator.logger import logger @@ -14,7 +15,6 @@ logger = logger.getChild(extension_name) class Help(commands.Cog): def __init__(self, bot: commands.Bot): self.bot = bot - self.purges = {} @commands.command("help", pass_context=True) async def help(self, ctx: commands.Context): @@ -48,7 +48,8 @@ class Help(commands.Cog): await ctx.message.add_reaction("\u2753") elif isinstance(error, MissingRequiredArgument) or isinstance(error, BadArgument): await ctx.message.add_reaction("\u274C") - elif isinstance(error, NotOwner) or isinstance(error, MissingPermissions): + elif isinstance(error, NotOwner) or isinstance(error, MissingPermissions)\ + or isinstance(error, NoPrivateMessage): await ctx.message.add_reaction("\u274C") else: await ctx.send("An error occurred !") diff --git a/extensions/presentation.py b/extensions/presentation.py index 1e78527..49a1c01 100644 --- a/extensions/presentation.py +++ b/extensions/presentation.py @@ -58,11 +58,12 @@ class Presentation(commands.Cog): @commands.Cog.listener() async def on_message(self, message: Message): - s = db.Session() - 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): - await message.author.add_roles(message.guild.get_role(p.role), reason="Presentation done") + if message.guild is not None: + s = db.Session() + 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): + await message.author.add_roles(message.guild.get_role(p.role), reason="Presentation done") def setup(bot): diff --git a/extensions/purge.py b/extensions/purge.py index eaba4ce..aff896c 100644 --- a/extensions/purge.py +++ b/extensions/purge.py @@ -41,17 +41,18 @@ class Purge(commands.Cog): @commands.Cog.listener() async def on_raw_reaction_add(self, payload: RawReactionActionEvent): - 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) - if user.id in self.purges: - if message.channel == self.purges[user.id].channel: - async with message.channel.typing(): - await message.channel.purge(before=self.purges[user.id], after=message, - limit=None) - await self.purges[user.id].delete() - await message.delete() - del self.purges[user.id] + if payload.guild_id: + 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) + if user.id in self.purges: + if message.channel == self.purges[user.id].channel: + async with message.channel.typing(): + await message.channel.purge(before=self.purges[user.id], after=message, + limit=None) + await self.purges[user.id].delete() + await message.delete() + del self.purges[user.id] def setup(bot):