diff --git a/minato_namikaze/bot_files/cogs/badges.py b/minato_namikaze/bot_files/cogs/badges.py index 79b6fe91..0b6482bc 100644 --- a/minato_namikaze/bot_files/cogs/badges.py +++ b/minato_namikaze/bot_files/cogs/badges.py @@ -3,7 +3,7 @@ import os import sys from io import BytesIO -from typing import Optional, Union, cast +from typing import Union import aiohttp import discord diff --git a/minato_namikaze/bot_files/cogs/img.py b/minato_namikaze/bot_files/cogs/img.py index 47132e88..6d09b4fa 100644 --- a/minato_namikaze/bot_files/cogs/img.py +++ b/minato_namikaze/bot_files/cogs/img.py @@ -1,4 +1,3 @@ -import datetime import os from asyncio import sleep from io import FileIO diff --git a/minato_namikaze/bot_files/cogs/moderation/moderation.py b/minato_namikaze/bot_files/cogs/moderation/moderation.py index 790273e0..a4f8cc74 100644 --- a/minato_namikaze/bot_files/cogs/moderation/moderation.py +++ b/minato_namikaze/bot_files/cogs/moderation/moderation.py @@ -1,7 +1,6 @@ -import datetime import re import shlex -from collections import Counter, defaultdict +from collections import Counter from os.path import join from typing import Optional, Union @@ -14,7 +13,6 @@ BannedMember, ErrorEmbed, MemberID, - PostStats, check_if_warning_system_setup, has_permissions, ) @@ -56,12 +54,11 @@ async def setdelay(self, ctx, seconds: int): @commands.bot_has_permissions(kick_members=True) @commands.guild_only() @commands.has_guild_permissions(kick_members=True) - async def kick(self, ctx, member: discord.Member, *, reason=None): + async def kick(self, ctx, member: Optional[Union[discord.Member, MemberID]], *, reason=None): """A command which kicks a given user""" await ctx.guild.kick(user=member, reason=reason) - embed = discord.Embed(title=f"{ctx.author.name} kicked: {member.name}", - description=reason) + embed = discord.Embed(title=f"{ctx.author.name} kicked: {member.name}", description=reason) await ctx.send(embed=embed) # ban @@ -86,7 +83,7 @@ async def ban( description="You **can't ban yourself**!")) return try: - await ctx.guild.ban(user=member, reason=reason) + await ctx.guild.ban(user=member, reason=ActionReason().convert(ctx, reason)) except: await ctx.send( embed=ErrorEmbed( @@ -96,8 +93,7 @@ async def ban( ) return - embed = ErrorEmbed(title=f"{ctx.author.name} banned: {member.name}", - description=reason) + embed = ErrorEmbed(title=f"{ctx.author.name} banned: {member.name}",description=reason) await ctx.send(embed=embed) # banlist @@ -242,8 +238,8 @@ async def softban(self, if reason is None: reason = f"Action done by {ctx.author} (ID: {ctx.author.id})" - await ctx.guild.ban(member, reason=reason) - await ctx.guild.unban(member, reason=reason) + await ctx.guild.ban(member, reason=ActionReason(ctx,reason)) + await ctx.guild.unban(member, reason=ActionReason(ctx,reason)) await ctx.send("\N{OK HAND SIGN}") # Unban @@ -268,7 +264,7 @@ async def unban(self, if reason is None: reason = f"Action done by {ctx.author} (ID: {ctx.author.id})" - await ctx.guild.unban(member.user, reason=reason) + await ctx.guild.unban(member.user, reason=ActionReason(reason)) if member.reason: await ctx.send( f"Unbanned {member.user} (ID: {member.user.id}), previously banned for {member.reason}." diff --git a/minato_namikaze/bot_files/lib/classes/converter.py b/minato_namikaze/bot_files/lib/classes/converter.py index 06850534..c8a009bd 100644 --- a/minato_namikaze/bot_files/lib/classes/converter.py +++ b/minato_namikaze/bot_files/lib/classes/converter.py @@ -78,8 +78,7 @@ async def convert(self, ctx, argument): "This member has not been banned before.") from None ban_list = await ctx.guild.bans() - entity = discord.utils.find(lambda u: str(u.user) == argument, - ban_list) + entity = discord.utils.find(lambda u: str(u.user) == argument,ban_list) if entity is None: raise commands.BadArgument( diff --git a/minato_namikaze/bot_files/lib/util/context.py b/minato_namikaze/bot_files/lib/util/context.py index a8cc134d..7c91e3a3 100644 --- a/minato_namikaze/bot_files/lib/util/context.py +++ b/minato_namikaze/bot_files/lib/util/context.py @@ -9,7 +9,7 @@ import TenGiphPy from discord.ext import commands -from .vars import ChannelAndMessageId, SetupVars, Tokens +from .vars import ChannelAndMessageId, SetupVars, Tokens, MemberID class ConfirmationView(discord.ui.View): @@ -212,20 +212,20 @@ def return_warning_channel(self, guild: Optional[discord.Guild]): topic=SetupVars.warns.value, ) - def get_user(self, user: Union[int, discord.Member]): - if isinstance(user, int): + def get_user(self, user: Union[int, discord.Member, MemberID]): + if isinstance(user, int) or isinstance(user, MemberID): user = self.bot.get_user(user) return user - async def get_dm(self, user: Union[int, discord.Member]): + async def get_dm(self, user: Union[int, discord.Member, MemberID]): try: - if isinstance(user, int): + if isinstance(user, int) or isinstance(user, MemberID): user = self.bot.get_or_fetch_member(user, self.guild) else: user = self.bot.get_or_fetch_member(user.id, self.guild) except: - if isinstance(user, int): - user = ctx.bot.get_user(user) + if isinstance(user, int) or isinstance(user, MemberID): + user = self.bot.get_user(user) return user.dm_channel if user.dm_channel else await user.create_dm() def get_roles(self, role: Union[int, discord.Role]): @@ -233,14 +233,12 @@ def get_roles(self, role: Union[int, discord.Role]): role = discord.utils.get(self.guild.roles, id=role) return role - def get_emoji(self, emoji: Union[int, discord.Emoji, - discord.PartialEmoji]): + def get_emoji(self, emoji: Union[int, discord.Emoji, discord.PartialEmoji]): if isinstance(emoji, int): emoji = discord.utils.get(self.guild.emojis, id=role) return emoji - def get_guild(self, guild: Union[int, discord.Guild, - discord.PartialInviteGuild]): + def get_guild(self, guild: Union[int, discord.Guild, discord.PartialInviteGuild]): if isinstance(guild, int): guild = self.bot.get_guild(guild) return guild