Skip to content

Commit

Permalink
action reason update
Browse files Browse the repository at this point in the history
  • Loading branch information
Dhruvacube committed Jan 15, 2022
1 parent 21f49b3 commit 11f4692
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 27 deletions.
2 changes: 1 addition & 1 deletion minato_namikaze/bot_files/cogs/badges.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion minato_namikaze/bot_files/cogs/img.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import datetime
import os
from asyncio import sleep
from io import FileIO
Expand Down
20 changes: 8 additions & 12 deletions minato_namikaze/bot_files/cogs/moderation/moderation.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -14,7 +13,6 @@
BannedMember,
ErrorEmbed,
MemberID,
PostStats,
check_if_warning_system_setup,
has_permissions,
)
Expand Down Expand Up @@ -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
Expand All @@ -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(
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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}."
Expand Down
3 changes: 1 addition & 2 deletions minato_namikaze/bot_files/lib/classes/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
20 changes: 9 additions & 11 deletions minato_namikaze/bot_files/lib/util/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -212,35 +212,33 @@ 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]):
if isinstance(role, int):
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
Expand Down

0 comments on commit 11f4692

Please sign in to comment.