async def report(self, ctx: Context, user: UserMemberConverter, *, reason: str): """ report a user """ user: Union[Member, User] if len(reason) > 900: raise CommandError(t.reason_too_long) if user == self.bot.user: raise UserCommandError(user, t.cannot_report) if user == ctx.author: raise UserCommandError(user, t.no_self_report) await Report.create(user.id, str(user), ctx.author.id, reason) server_embed = Embed(title=t.report, description=t.reported_response, colour=Colors.ModTools) server_embed.set_author(name=str(user), icon_url=user.display_avatar.url) await reply(ctx, embed=server_embed) await send_to_changelog_mod(ctx.guild, ctx.message, Colors.report, t.log_reported, user, reason)
async def unban(self, ctx: Context, user: UserMemberConverter, *, reason: str): """ unban a user """ user: Union[Member, User] if len(reason) > 900: raise CommandError(t.reason_too_long) if not ctx.guild.me.guild_permissions.ban_members: raise CommandError(t.cannot_unban_permissions) was_banned = True try: await ctx.guild.unban(user, reason=reason) except HTTPException: was_banned = False async for ban in await db.stream( filter_by(Ban, active=True, member=user.id)): was_banned = True await Ban.deactivate(ban.id, ctx.author.id, reason) if not was_banned: raise UserCommandError(user, t.not_banned) server_embed = Embed(title=t.unban, description=t.unbanned_response, colour=Colors.ModTools) server_embed.set_author(name=str(user), icon_url=user.display_avatar.url) await reply(ctx, embed=server_embed) await send_to_changelog_mod(ctx.guild, ctx.message, Colors.unban, t.log_unbanned, user, reason)
async def unmute(self, ctx: Context, user: UserMemberConverter, *, reason: str): """ unmute a user """ user: Union[Member, User] if len(reason) > 900: raise CommandError(t.reason_too_long) mute_role: Role = await get_mute_role(ctx.guild) was_muted = False if isinstance(user, Member) and mute_role in user.roles: was_muted = True check_role_assignable(mute_role) await user.remove_roles(mute_role) async for mute in await db.stream( filter_by(Mute, active=True, member=user.id)): await Mute.deactivate(mute.id, ctx.author.id, reason) was_muted = True if not was_muted: raise UserCommandError(user, t.not_muted) server_embed = Embed(title=t.unmute, description=t.unmuted_response, colour=Colors.ModTools) server_embed.set_author(name=str(user), icon_url=user.display_avatar.url) await reply(ctx, embed=server_embed) await send_to_changelog_mod(ctx.guild, ctx.message, Colors.unmute, t.log_unmuted, user, reason)
async def warn(self, ctx: Context, user: UserMemberConverter, *, reason: str): """ warn a user """ user: Union[Member, User] if len(reason) > 900: raise CommandError(t.reason_too_long) if user == self.bot.user: raise UserCommandError(user, t.cannot_warn) user_embed = Embed(title=t.warn, description=t.warned(ctx.author.mention, ctx.guild.name, reason), colour=Colors.ModTools) server_embed = Embed(title=t.warn, description=t.warned_response, colour=Colors.ModTools) server_embed.set_author(name=str(user), icon_url=user.display_avatar.url) try: await user.send(embed=user_embed) except (Forbidden, HTTPException): server_embed.description = t.no_dm + "\n\n" + server_embed.description server_embed.colour = Colors.error await Warn.create(user.id, str(user), ctx.author.id, reason) await reply(ctx, embed=server_embed) await send_to_changelog_mod(ctx.guild, ctx.message, Colors.warn, t.log_warned, user, reason)
async def kick(self, ctx: Context, member: Member, *, reason: str): """ kick a member """ if len(reason) > 900: raise CommandError(t.reason_too_long) if member == self.bot.user or await is_teamler(member): raise UserCommandError(member, t.cannot_kick) if not ctx.guild.me.guild_permissions.kick_members: raise CommandError(t.cannot_kick_permissions) if member.top_role >= ctx.guild.me.top_role or member.id == ctx.guild.owner_id: raise UserCommandError(member, t.cannot_kick) await Kick.create(member.id, str(member), ctx.author.id, reason) await send_to_changelog_mod(ctx.guild, ctx.message, Colors.kick, t.log_kicked, member, reason) user_embed = Embed(title=t.kick, description=t.kicked(ctx.author.mention, ctx.guild.name, reason), colour=Colors.ModTools) server_embed = Embed(title=t.kick, description=t.kicked_response, colour=Colors.ModTools) server_embed.set_author(name=str(member), icon_url=member.display_avatar.url) try: await member.send(embed=user_embed) except (Forbidden, HTTPException): server_embed.description = t.no_dm + "\n\n" + server_embed.description server_embed.colour = Colors.error await member.kick(reason=reason) await revoke_verification(member) await reply(ctx, embed=server_embed)
async def ban(self, ctx: Context, user: UserMemberConverter, ban_days: DurationConverter, delete_days: int, *, reason: str): """ ban a user set ban_days to `inf` for a permanent ban """ ban_days: Optional[int] user: Union[Member, User] if not ctx.guild.me.guild_permissions.ban_members: raise CommandError(t.cannot_ban_permissions) if len(reason) > 900: raise CommandError(t.reason_too_long) if not 0 <= delete_days <= 7: raise CommandError(tg.invalid_duration) if user == self.bot.user or await is_teamler(user): raise UserCommandError(user, t.cannot_ban) if isinstance(user, Member) and (user.top_role >= ctx.guild.me.top_role or user.id == ctx.guild.owner_id): raise UserCommandError(user, t.cannot_ban) active_bans: List[Ban] = await db.all( filter_by(Ban, active=True, member=user.id)) for ban in active_bans: if ban.days == -1: raise UserCommandError(user, t.already_banned) ts = ban.timestamp + timedelta(days=ban.days) if ban_days is not None and utcnow() + timedelta( days=ban_days) <= ts: raise UserCommandError(user, t.already_banned) for ban in active_bans: await Ban.upgrade(ban.id, ctx.author.id) async for mute in await db.stream( filter_by(Mute, active=True, member=user.id)): await Mute.upgrade(mute.id, ctx.author.id) user_embed = Embed(title=t.ban, colour=Colors.ModTools) server_embed = Embed(title=t.ban, description=t.banned_response, colour=Colors.ModTools) server_embed.set_author(name=str(user), icon_url=user.display_avatar.url) if ban_days is not None: await Ban.create(user.id, str(user), ctx.author.id, ban_days, reason, bool(active_bans)) user_embed.description = t.banned(ctx.author.mention, ctx.guild.name, reason, cnt=ban_days) await send_to_changelog_mod( ctx.guild, ctx.message, Colors.ban, t.log_banned, user, reason, duration=t.log_field.days(cnt=ban_days)) else: await Ban.create(user.id, str(user), ctx.author.id, -1, reason, bool(active_bans)) user_embed.description = t.banned_inf(ctx.author.mention, ctx.guild.name, reason) await send_to_changelog_mod(ctx.guild, ctx.message, Colors.ban, t.log_banned, user, reason, duration=t.log_field.days_infinity) try: await user.send(embed=user_embed) except (Forbidden, HTTPException): server_embed.description = t.no_dm + "\n\n" + server_embed.description server_embed.colour = Colors.error await ctx.guild.ban(user, delete_message_days=delete_days, reason=reason) await revoke_verification(user) await reply(ctx, embed=server_embed)
async def mute(self, ctx: Context, user: UserMemberConverter, days: DurationConverter, *, reason: str): """ mute a user set days to `inf` for a permanent mute """ user: Union[Member, User] days: Optional[int] if len(reason) > 900: raise CommandError(t.reason_too_long) mute_role: Role = await get_mute_role(ctx.guild) if user == self.bot.user or await is_teamler(user): raise UserCommandError(user, t.cannot_mute) if isinstance(user, Member): check_role_assignable(mute_role) await user.add_roles(mute_role) await user.move_to(None) active_mutes: List[Mute] = await db.all( filter_by(Mute, active=True, member=user.id)) for mute in active_mutes: if mute.days == -1: raise UserCommandError(user, t.already_muted) ts = mute.timestamp + timedelta(days=mute.days) if days is not None and utcnow() + timedelta(days=days) <= ts: raise UserCommandError(user, t.already_muted) for mute in active_mutes: await Mute.upgrade(mute.id, ctx.author.id) user_embed = Embed(title=t.mute, colour=Colors.ModTools) server_embed = Embed(title=t.mute, description=t.muted_response, colour=Colors.ModTools) server_embed.set_author(name=str(user), icon_url=user.display_avatar.url) if days is not None: await Mute.create(user.id, str(user), ctx.author.id, days, reason, bool(active_mutes)) user_embed.description = t.muted(ctx.author.mention, ctx.guild.name, reason, cnt=days) await send_to_changelog_mod(ctx.guild, ctx.message, Colors.mute, t.log_muted, user, reason, duration=t.log_field.days(cnt=days)) else: await Mute.create(user.id, str(user), ctx.author.id, -1, reason, bool(active_mutes)) user_embed.description = t.muted_inf(ctx.author.mention, ctx.guild.name, reason) await send_to_changelog_mod(ctx.guild, ctx.message, Colors.mute, t.log_muted, user, reason, duration=t.log_field.days_infinity) try: await user.send(embed=user_embed) except (Forbidden, HTTPException): server_embed.description = t.no_dm + "\n\n" + server_embed.description server_embed.colour = Colors.error await reply(ctx, embed=server_embed)