Fix private messages
This commit is contained in:
parent
8fda6e37bb
commit
14f2ab7e3f
3 changed files with 22 additions and 19 deletions
|
@ -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 !")
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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):
|
||||
|
|
Reference in a new issue