async def on_raw_reaction_add(payload): params = getParams() message = payload.message_id member = payload.member emoji = payload.emoji guild = member.guild channelId = payload.channel_id try: if message == params['rulesMessageId'] and emoji.name == params[ 'emojiNameToAcceptRules']: if await hasRoles(member, params['onAcceptRulesRolesToRemove']): await removeRoles(bot, member, params['onAcceptRulesRolesToRemove']) await addRoles(bot, member, params['onAcceptRulesRolesToAdd']) if message == params['rolesMessageID']: categories = guild.categories channel = find(lambda c: c.id == channelId, guild.channels) messageWithReaction = await channel.fetch_message(message) categoryId = channel.category_id category = find(lambda cc: cc.id == categoryId, categories) await messageWithReaction.remove_reaction(emoji, member) roles = params['roles'] role = find(lambda r: r['emoji'] == str(emoji), roles) if role: if await hasRoles(member, role['roleName']): await removeRoles(bot, member, role['roleName']) else: await addRoles(bot, member, role['roleName']) aw except KeyError as error: print(error) except Exception as error: print(error)
async def clear(self, ctx, number: int = 10): try: author = ctx.author guild = ctx.message.guild channel = ctx.channel # Check if author is a user (i.e. not a bot) if not author.bot: params = getParams() roles = params['rolesThatCanClear'] # Check if author has permissions to perform this command if await hasAtLeastOneRole(author, roles): if number > 0: deleted = await channel.purge(limit=number) logsChannel = find( lambda c: c.id == params['logsChannelId'], guild.channels) if logsChannel: await logsChannel.send( '{} a supprimé {} message(s) du channel "{}".'. format(author.name, len(deleted), channel.name)) else: await ctx.send( "Vous n'avez pas les permissions pour effectuer cette commande. Si vous pensez que c'est une erreur, veuillez contacter un administrateur." ) else: await ctx.send( "Cette commande ne peut être effectuée par un bot.") except KeyError as error: print(error) except Exception as error: print(error)
async def unmute(self, ctx, member: discord.Member): try: author = ctx.author guild = ctx.message.guild # Check if author is a user (i.e. not a bot) if not author.bot: params = getParams() roles = params['rolesThatCanMute'] # Check if author has permissions to perform this command if await hasAtLeastOneRole(author, roles): # Check if the target is a user (i.e. not a bot) if not member.bot: embed = discord.Embed(colour=discord.Colour.purple()) embed.set_author( name=self.bot.user.display_name + ' • UnMute', icon_url=params['punishmentsAuthorImageUrl']) # embed.set_thumbnail(url='https://mxcommunity.xyz/src/MxCommunity_tr.png') embed.add_field(name='Membre unmute', value=member, inline=False) embed.add_field(name='Unmute par', value=author, inline=False) await unmuteMember(member, guild, params) # await ctx.send(embed=embed) # TODO Verify if user is already muted and if so send a message to tell the author the target is already muted # TODO Actually mute the user until endDate (i.e. mute now and unmute at the end of the punishment by making sure that shutting server won't break everything) # Send message to the punishments channel to have a record of the punishment if guild: channel = find( lambda c: c.id == params['punishmentsChannelId' ], guild.channels) if channel: await channel.send(embed=embed) # Send message to the user so that he knows he got unmuted await member.send(embed=embed) else: await ctx.send( "Vous ne pouvez pas unmute un bot. Veuillez réessayer avec un utilisateur valide." ) else: await ctx.send( "Vous n'avez pas les permissions pour effectuer cette commande. Si vous pensez que c'est une erreur, veuillez contacter un administrateur." ) else: await ctx.send( "Cette commande ne peut être effectuée par un bot.") except KeyError as error: print(error) except Exception as error: print(error)
import sys from discord.utils import get, find from discord.ext import commands from dotenv import load_dotenv from fileFinder import FileFinder from paramsGetter import getParams from rolesHandler import hasRoles, addRoles, removeRoles print("Start...") bot = discord.Client() bot = commands.Bot(command_prefix='&') load_dotenv() params = getParams() @bot.event async def on_ready(): print("Lily's Secretary : ON") print("Version : 1.0.3") await bot.change_presence( status=discord.Status.idle, activity=discord.Game("Secrétaire Officiel De la MxCommunity")) @bot.event async def on_command_error(ctx, exception): await ctx.send(str(exception))
async def kick(self, ctx, member: discord.Member, *reasons): try: author = ctx.author # Check if author is a user (i.e. not a bot) if not author.bot: params = getParams() roles = params['rolesThatCanKick'] # Check if author has permissions to perform this command if await hasAtLeastOneRole(author, roles): # Check if the target is a user (i.e. not a bot) if not member.bot: rolesToAvoid = params['rolesThatCannotBeKicked'] # Check if the target can receive this command if not await hasAtLeastOneRole(member, rolesToAvoid): reasonMsg = reasonMsg = ' '.join( reasons) if reasons else '' embed = discord.Embed( colour=discord.Colour.purple()) embed.set_author( name=self.bot.user.display_name + ' • Kick', icon_url=params['punishmentsAuthorImageUrl']) # embed.set_author(name=self.bot.user.display_name + ' • Kick ✅', icon_url=params['punishmentsAuthorImageUrl']) # embed.set_thumbnail(url='https://mxcommunity.xyz/src/MxCommunity_tr.png') embed.add_field(name='Membre kick', value=member, inline=False) embed.add_field(name='Kick par', value=author, inline=False) if reasons: embed.add_field(name='Raison', value=reasonMsg, inline=False) # Send message to the punishments channel to have a record of the punishment guildId = await getGuildId() guild = find(lambda g: g.id == guildId, self.bot.guilds) if guild: channel = find( lambda c: c.id == params[ 'punishmentsChannelId'], guild.channels) if channel: await channel.send(embed=embed) # Send message to the user so that he knows why he got kicked await member.send(embed=embed) # Actually kick him await member.kick(reason=reasonMsg) else: await ctx.send( "Vous ne pouvez pas kick cet utilisateur à cause des rôles qui lui sont attribués." ) else: await ctx.send( "Vous ne pouvez pas kick un bot. Veuillez réessayer avec un utilisateur valide." ) else: await ctx.send( "Vous n'avez pas les permissions pour effectuer cette commande. Si vous pensez que c'est une erreur, veuillez contacter un administrateur." ) else: await ctx.send( "Cette commande ne peut être effectuée par un bot.") except KeyError as error: print(error) except Exception as error: print(error)
async def mute(self, ctx, member: discord.Member, *args): try: author = ctx.author guild = ctx.message.guild # Check if author is a user (i.e. not a bot) if not author.bot: params = getParams() roles = params['rolesThatCanMute'] # Check if author has permissions to perform this command if await hasAtLeastOneRole(author, roles): # Check if the target is a user (i.e. not a bot) if not member.bot: rolesToAvoid = params['rolesThatCannotBeMuted'] # Check if the target can receive this command if not await hasAtLeastOneRole(member, rolesToAvoid): # Check if target is already being muted if not await alreadyMuted(member, guild, params): embed = discord.Embed( colour=discord.Colour.purple()) embed.set_author( name=self.bot.user.display_name + ' • Mute', icon_url=params[ 'punishmentsAuthorImageUrl']) # embed.set_thumbnail(url='https://mxcommunity.xyz/src/MxCommunity_tr.png') embed.add_field(name='Membre mute', value=member, inline=False) embed.add_field(name='Mute par', value=author, inline=False) endDate = None endMessage = 'Indéfini' if args: endDate, index = self.timeParser.endDate( args) if endDate: endMessage = '{} {} {} à {}'.format( endDate.day, self.timeParser.getMonthName( endDate.month), endDate.year, endDate.strftime("%H:%M:%S")) embed.add_field(name='Fin de la sanction', value=endMessage, inline=False) reasons = args[index:] if reasons: reasonMsg = reasonMsg = ' '.join( reasons) if reasons else '' embed.add_field(name='Raison', value=reasonMsg, inline=False) else: embed.add_field(name='Fin de la sanction', value=endMessage, inline=False) # await ctx.send(embed=embed) # TODO Verify if user is already muted and if so send a message to tell the author the target is already muted # TODO Actually mute the user until endDate (i.e. mute now and unmute at the end of the punishment by making sure that shutting server won't break everything) # Send message to the punishments channel to have a record of the punishment if guild: channel = find( lambda c: c.id == params[ 'punishmentsChannelId'], guild.channels) if channel: await channel.send(embed=embed) # Send message to the user so that he knows why he got muted await member.send(embed=embed) # Actually mute the member await muteMember(member, guild, endDate, params) else: await ctx.send( "Cet utilisateur est déjà mute. Vous ne pouvez donc pas effectuer cette commande." ) else: await ctx.send( "Vous ne pouvez pas mute cet utilisateur à cause des rôles qui lui sont attribués." ) else: await ctx.send( "Vous ne pouvez pas mute un bot. Veuillez réessayer avec un utilisateur valide." ) else: await ctx.send( "Vous n'avez pas les permissions pour effectuer cette commande. Si vous pensez que c'est une erreur, veuillez contacter un administrateur." ) else: await ctx.send( "Cette commande ne peut être effectuée par un bot.") except KeyError as error: print(error) except Exception as error: print(error)