Exemplo n.º 1
0
    async def kick(self, ctx, member: discord.Member, *, reason: str = None):
        """Kick a member."""

        try:
            await ctx.message.delete()
        except discord.errors.NotFound:
            pass

        if checks.has_any_role(member, *self.protected_roles):
            return await ctx.send(f'That member has a protected role.')

        if await self.bot.is_owner(member):
            return

        await self.log_action(ctx.guild,
                              'kick',
                              member,
                              ctx.author,
                              datetime.datetime.utcnow(),
                              reason=reason)

        try:
            await member.send(
                f'You have been kicked from **{ctx.guild.name}**.\n**Reason:** {reason}'
            )
        except discord.errors.Forbidden:
            pass

        await ctx.send(
            f'{member.mention} has been kicked.\n**Reason:** {reason}')

        await member.kick(reason=reason)
Exemplo n.º 2
0
    async def ban(self,
                  ctx,
                  member: converters.UserConverter,
                  *,
                  reason: str = None):
        """Ban a member."""

        try:
            await ctx.message.delete()
        except discord.errors.NotFound:
            pass

        guild_member = ctx.guild.get_member(member.id)

        if guild_member is not None and checks.has_any_role(
                guild_member, *self.protected_roles):
            return await ctx.send(f'That member has a protected role.')

        if await self.bot.is_owner(member):
            return

        query = 'SELECT timer_id FROM mod_tempactions WHERE user_id = $1 AND action = $2;'
        record = await self.bot.pool.fetchrow(query, member.id, 'tempban')

        if record is not None:
            timer_id = record['timer_id']

            timers = self.bot.get_cog('Timers')
            if timers is None:
                return await ctx.send('Timers module is not loaded.')
            else:
                await timers.remove_timer(timer_id)

        await self.log_action(ctx.guild,
                              'ban',
                              member,
                              ctx.author,
                              datetime.datetime.utcnow(),
                              reason=reason)

        if guild_member is not None:
            try:
                await member.send(
                    f'You have been banned from **{ctx.guild.name}**.\n**Reason:** {reason}'
                )
            except discord.errors.Forbidden:
                pass

        await ctx.send(
            f'{member.mention} has been banned.\n**Reason:** {reason}')

        await ctx.guild.ban(member, reason=reason, delete_message_days=0)
Exemplo n.º 3
0
    async def tempban(self,
                      ctx,
                      member: converters.UserConverter,
                      duration: time.ShortTime,
                      *,
                      reason: str = None):
        """Temporarily ban a member."""

        try:
            await ctx.message.delete()
        except discord.errors.NotFound:
            pass

        guild_member = ctx.guild.get_member(member.id)

        if guild_member is not None and checks.has_any_role(
                guild_member, *self.protected_roles):
            return await ctx.send(f'That member has a protected role.')

        if await self.bot.is_owner(member):
            return

        await self.temp_action('tempban', member, duration)

        await self.log_action(ctx.guild,
                              'tempban',
                              member,
                              ctx.author,
                              datetime.datetime.utcnow(),
                              duration=duration,
                              reason=reason)

        if guild_member is not None:
            try:
                await member.send(
                    f'You have been temporarily banned from **{ctx.guild.name}** for {time.human_timedelta(duration.delta)}.\n**Reason:** {reason}'
                )
            except discord.errors.Forbidden:
                pass

        await ctx.send(
            f'{member.mention} has been temporarily banned for {time.human_timedelta(duration.delta)}.\n**Reason:** {reason}'
        )

        await ctx.guild.ban(member, reason=reason, delete_message_days=0)
Exemplo n.º 4
0
    async def unmute(self, ctx, member: discord.Member, *, reason: str = None):
        """Unmute a member."""

        try:
            await ctx.message.delete()
        except discord.errors.NotFound:
            pass

        if checks.has_any_role(member, *self.protected_roles):
            return await ctx.send(f'That member has a protected role.')

        if await self.bot.is_owner(member):
            return

        query = 'SELECT timer_id FROM mod_tempactions WHERE user_id = $1 AND action = $2;'
        record = await self.bot.pool.fetchrow(query, member.id, 'tempmute')

        if record is not None:
            timer_id = record['timer_id']

            timers = self.bot.get_cog('Timers')
            if timers is None:
                return await ctx.send('Timers module is not loaded.')
            else:
                await timers.remove_timer(timer_id)

        await self.log_action(ctx.guild,
                              'unmute',
                              member,
                              ctx.author,
                              datetime.datetime.utcnow(),
                              reason=reason)

        try:
            await member.send(
                f'You have been unmuted in **{ctx.guild.name}**.\n**Reason:** {reason}'
            )
        except discord.errors.Forbidden:
            pass

        role = discord.utils.get(ctx.guild.roles, name=self.mute_role)
        await member.remove_roles(role, reason=reason)

        await ctx.send(
            f'{member.mention} has been unmuted.\n**Reason:** {reason}')
Exemplo n.º 5
0
    async def unban(self,
                    ctx,
                    member: converters.UserConverter,
                    *,
                    reason: str = None):
        """Unban a member."""

        try:
            await ctx.message.delete()
        except discord.errors.NotFound:
            pass

        guild_member = ctx.guild.get_member(member.id)

        if guild_member is not None and checks.has_any_role(
                guild_member, *self.protected_roles):
            return await ctx.send(f'That member has a protected role.')

        if await self.bot.is_owner(member):
            return

        if await ctx.guild.get_ban(member) is None:
            return await ctx.send(f'That member is not banned.')

        query = "SELECT timer_id FROM mod_tempactions WHERE user_id = $1 AND action = $2;"
        record = await self.bot.pool.fetchrow(query, member.id, 'tempban')

        if record is not None:
            timer_id = record['timer_id']

            timers = self.bot.get_cog('Timers')
            if timers is None:
                return await ctx.send('Timers module is not loaded.')
            else:
                await timers.remove_timer(timer_id)

        await self.log_action(ctx.guild,
                              'unban',
                              member,
                              ctx.author,
                              datetime.datetime.utcnow(),
                              reason=reason)

        await ctx.guild.unban(member, reason=reason)
Exemplo n.º 6
0
    async def tempmute(self,
                       ctx,
                       member: discord.Member,
                       duration: time.ShortTime,
                       *,
                       reason: str = None):
        """Temporarily mute a member."""

        try:
            await ctx.message.delete()
        except discord.errors.NotFound:
            pass

        if checks.has_any_role(member, *self.protected_roles):
            return await ctx.send(f'That member has a protected role.')

        if await self.bot.is_owner(member):
            return

        await self.temp_action('tempmute', member, duration)

        await self.log_action(ctx.guild,
                              'tempmute',
                              member,
                              ctx.author,
                              datetime.datetime.utcnow(),
                              duration=duration,
                              reason=reason)

        try:
            await member.send(
                f'You have been temporarily muted in **{ctx.guild.name}** for {time.human_timedelta(duration.delta)}.\n**Reason:** {reason}'
            )
        except discord.errors.Forbidden:
            pass

        role = discord.utils.get(ctx.guild.roles, name=self.mute_role)
        await member.add_roles(role, reason=reason)

        await ctx.send(
            f'{member.mention} has been temporarily muted for {time.human_timedelta(duration.delta)}.\n**Reason:** {reason}'
        )