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 import Embed
|
||||||
from discord.ext import commands
|
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 import config
|
||||||
from administrator.logger import logger
|
from administrator.logger import logger
|
||||||
|
@ -14,7 +15,6 @@ logger = logger.getChild(extension_name)
|
||||||
class Help(commands.Cog):
|
class Help(commands.Cog):
|
||||||
def __init__(self, bot: commands.Bot):
|
def __init__(self, bot: commands.Bot):
|
||||||
self.bot = bot
|
self.bot = bot
|
||||||
self.purges = {}
|
|
||||||
|
|
||||||
@commands.command("help", pass_context=True)
|
@commands.command("help", pass_context=True)
|
||||||
async def help(self, ctx: commands.Context):
|
async def help(self, ctx: commands.Context):
|
||||||
|
@ -48,7 +48,8 @@ class Help(commands.Cog):
|
||||||
await ctx.message.add_reaction("\u2753")
|
await ctx.message.add_reaction("\u2753")
|
||||||
elif isinstance(error, MissingRequiredArgument) or isinstance(error, BadArgument):
|
elif isinstance(error, MissingRequiredArgument) or isinstance(error, BadArgument):
|
||||||
await ctx.message.add_reaction("\u274C")
|
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")
|
await ctx.message.add_reaction("\u274C")
|
||||||
else:
|
else:
|
||||||
await ctx.send("An error occurred !")
|
await ctx.send("An error occurred !")
|
||||||
|
|
|
@ -58,11 +58,12 @@ class Presentation(commands.Cog):
|
||||||
|
|
||||||
@commands.Cog.listener()
|
@commands.Cog.listener()
|
||||||
async def on_message(self, message: Message):
|
async def on_message(self, message: Message):
|
||||||
s = db.Session()
|
if message.guild is not None:
|
||||||
p = s.query(db.Presentation).filter(db.Presentation.guild == message.guild.id).first()
|
s = db.Session()
|
||||||
s.close()
|
p = s.query(db.Presentation).filter(db.Presentation.guild == message.guild.id).first()
|
||||||
if p and p.channel == message.channel.id and p.role not in map(lambda x: x.id, message.author.roles):
|
s.close()
|
||||||
await message.author.add_roles(message.guild.get_role(p.role), reason="Presentation done")
|
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):
|
def setup(bot):
|
||||||
|
|
|
@ -41,17 +41,18 @@ class Purge(commands.Cog):
|
||||||
|
|
||||||
@commands.Cog.listener()
|
@commands.Cog.listener()
|
||||||
async def on_raw_reaction_add(self, payload: RawReactionActionEvent):
|
async def on_raw_reaction_add(self, payload: RawReactionActionEvent):
|
||||||
user = self.bot.get_user(payload.user_id)
|
if payload.guild_id:
|
||||||
message = await self.bot.get_guild(payload.guild_id).get_channel(payload.channel_id)\
|
user = self.bot.get_user(payload.user_id)
|
||||||
.fetch_message(payload.message_id)
|
message = await self.bot.get_guild(payload.guild_id).get_channel(payload.channel_id)\
|
||||||
if user.id in self.purges:
|
.fetch_message(payload.message_id)
|
||||||
if message.channel == self.purges[user.id].channel:
|
if user.id in self.purges:
|
||||||
async with message.channel.typing():
|
if message.channel == self.purges[user.id].channel:
|
||||||
await message.channel.purge(before=self.purges[user.id], after=message,
|
async with message.channel.typing():
|
||||||
limit=None)
|
await message.channel.purge(before=self.purges[user.id], after=message,
|
||||||
await self.purges[user.id].delete()
|
limit=None)
|
||||||
await message.delete()
|
await self.purges[user.id].delete()
|
||||||
del self.purges[user.id]
|
await message.delete()
|
||||||
|
del self.purges[user.id]
|
||||||
|
|
||||||
|
|
||||||
def setup(bot):
|
def setup(bot):
|
||||||
|
|
Reference in a new issue