예제 #1
0
    async def on_member_remove(self, member):
        guild = member.guild
        sql = "INSERT INTO `join_leave` (`user_id`, `guild`, `value`) VALUES " \
              "(:user_id, :guild, :value) ON DUPLICATE KEY UPDATE value=-1"

        self._q.put_nowait((sql, {
            'user_id': member.id,
            'guild': guild.id,
            'value': -1
        }))

        channel = self.bot.guild_cache.leave_channel(guild.id)
        channel = guild.get_channel(channel)
        if channel is None:
            return

        message = self.bot.guild_cache.leave_message(guild.id,
                                                     default_message=True)
        if not message:
            return

        perms = channel.permissions_for(
            channel.guild.get_member(self.bot.user.id))
        if not perms.send_messages:
            return

        message = format_join_leave(member, message)
        await channel.send(message)
예제 #2
0
    async def on_member_join(self, member):
        guild = member.guild
        sql = "INSERT INTO `join_leave` (`user_id`, `guild`, `value`) VALUES " \
              "(:user_id, :guild, :value) ON DUPLICATE KEY UPDATE value=1"

        self._q.put_nowait((sql, {
            'user_id': member.id,
            'guild': guild.id,
            'value': 1
        }))

        channel = self.bot.guild_cache.join_channel(guild.id)
        channel = guild.get_channel(channel)
        if channel is None:
            return

        message = self.bot.guild_cache.join_message(guild.id,
                                                    default_message=True)
        if not message:
            return

        perms = channel.permissions_for(
            channel.guild.get_member(self.bot.user.id))
        if not perms.send_messages:
            return

        if member.id == 287664210152783873:
            message = 'Cease the tag %s' % member.mention
        else:
            message = format_join_leave(member, message)

        await channel.send(message)
예제 #3
0
    async def test_join_format(self, ctx, *, join_message):
        formatted = format_join_leave(ctx.author, join_message)
        if len(formatted) > 1000:
            return await ctx.send(
                'The message generated using this format is too long. Please reduce the amount of text/variables'
            )

        await ctx.send(formatted)
예제 #4
0
    async def join_set(self, ctx, *, message):
        """Set the welcome message on this server
        See {prefix}formatting for help on formatting the message"""
        guild = ctx.guild
        try:
            formatted = format_join_leave(ctx.author, message)
        except Exception as e:
            return await ctx.send(
                'Failed to use format because it returned an error.```py\n{}```'
                .format(e))

        if len(formatted) > 1000:
            return await ctx.send(
                'The message generated using this format is too long. Please reduce the amount of text/variables'
            )

        success = await self.cache.set_join_message(guild.id, message)
        if not success:
            await ctx.send('Failed to set message format because of an error')
        else:
            await ctx.send('Successfully set the message format')
예제 #5
0
    async def leave_set(self, ctx, *, message):
        """Set the leave message on this server
        See {prefix}join_format for help on formatting the message"""
        guild = ctx.guild
        try:
            formatted = format_join_leave(ctx.author, message)
        except (AttributeError, KeyError) as e:
            return await ctx.send(
                'Failed to use format because it returned an error.```py\n{}```'
                .format(e))

        splitted = split_string(formatted, splitter='\n')
        if len(splitted) > 1:
            return await ctx.send(
                'The message generated using this format is too long. Please reduce the amount of text/variables'
            )

        success = await self.cache.set_leave_message(guild.id, message)
        if not success:
            await ctx.send('Failed to set message format because of an error')
        else:
            await ctx.send('Successfully set the message format')