[Mod] Added voice kicking. (#2639)

* Added voice kicking.

* Reversed exceptions.

* Lets use a check that works for this task 👀

* Update abc.py

* Black formatting
This commit is contained in:
Kowlin 2019-05-03 16:08:25 +02:00 committed by Michael H
parent 16990071cb
commit 9414de24d4
3 changed files with 63 additions and 0 deletions

View File

@ -20,6 +20,13 @@ class MixinMeta(ABC):
self.ban_queue: List[Tuple[int, int]]
self.unban_queue: List[Tuple[int, int]]
@staticmethod
@abstractmethod
async def _voice_perm_check(
ctx: commands.Context, user_voice_state: Optional[discord.VoiceState], **perms: bool
) -> bool:
raise NotImplementedError()
@classmethod
@abstractmethod
async def get_audit_entry_info(

View File

@ -97,4 +97,10 @@ CASETYPES = [
"case_str": "Server Unmute",
"audit_type": "overwrite_update",
},
{
"name": "vkick",
"default_setting": False,
"image": "\N{SPEAKER WITH CANCELLATION STROKE}",
"case_str": "Voice Kick",
},
]

View File

@ -495,6 +495,56 @@ class KickBanMixin(MixinMeta):
await ctx.send(e)
await ctx.send(_("Done. Enough chaos."))
@commands.command()
@commands.guild_only()
@commands.mod_or_permissions(move_members=True)
async def voicekick(
self, ctx: commands.Context, member: discord.Member, *, reason: str = None
):
"""Kick a member from a voice channel."""
author = ctx.author
guild = ctx.guild
user_voice_state: discord.VoiceState = member.voice
if await self._voice_perm_check(ctx, user_voice_state, move_members=True) is False:
return
elif not await is_allowed_by_hierarchy(self.bot, self.settings, guild, author, member):
await ctx.send(
_(
"I cannot let you do that. You are "
"not higher than the user in the role "
"hierarchy."
)
)
return
case_channel = member.voice.channel
# Store this channel for the case channel.
try:
await member.move_to(discord.Object(id=None))
# Work around till we get D.py 1.1.0, whereby we can directly do None.
except discord.Forbidden: # Very unlikely that this will ever occur
await ctx.send(_("I am unable to kick this member from the voice channel."))
return
except discord.HTTPException:
await ctx.send(_("Something went wrong while attempting to kick that member"))
return
else:
try:
await modlog.create_case(
self.bot,
guild,
ctx.message.created_at,
"vkick",
member,
author,
reason,
until=None,
channel=case_channel,
)
except RuntimeError as e:
await ctx.send(e)
@commands.command()
@commands.guild_only()
@commands.bot_has_permissions(ban_members=True)