From 53c8eef2248f3f0e7da9057e679f224418b70a9c Mon Sep 17 00:00:00 2001 From: Siphalor Date: Mon, 25 Oct 2021 20:12:55 +0200 Subject: [PATCH] =?UTF-8?q?Add=20Hall=C3=B6hl=20(Pull=20to=20L=C3=B6h)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bot.py | 62 +++++++++++++++++++++++++++++++++++++++++++++++++--- lib/utils.py | 3 +-- 2 files changed, 60 insertions(+), 5 deletions(-) diff --git a/bot.py b/bot.py index f91d4c2..374c5ee 100644 --- a/bot.py +++ b/bot.py @@ -9,7 +9,8 @@ import discord from discord.ext import commands from discord.ext.commands import MemberConverter from discord_slash import SlashCommand, SlashContext, SlashCommandOptionType -from discord_slash.utils.manage_commands import create_option, create_choice +from discord_slash.model import SlashCommandPermissionType +from discord_slash.utils.manage_commands import create_option, create_choice, create_permission from dotenv import load_dotenv from lib.config import config, config_load, config_save, config_get, config_set, config_get_descriptions, \ @@ -50,8 +51,11 @@ TOPFIT_WORDS = ( # LOEH_ID = 327126546970312739 LOEH_ID = 254265844928872448 +LOEH_CHANNEL_ID = 900327877327867944 OWNER_ID = 327126546970312739 +INF19X_GUILD_ID = 651348951538335744 + OCH_LOEH_SOUND = "assets/och_loeh.mp3" config_load() @@ -281,7 +285,7 @@ async def config_prefix_command(ctx: commands.Context, cmd: str = '', key: str = # ------------------- The slashy way of life ------------------- # -slash_guild_ids = None +slash_guild_ids = [ 785415257308004422 ] config_choices = [create_choice(name=entry[1][1], value=entry[0]) for entry in config_meta.items() if entry[1][0]] config_option = create_option("config_key", "A key identifying the config entry to target", str, True, config_choices) @@ -418,12 +422,64 @@ async def list_messages_slash(ctx: SlashContext, channel: Optional[discord.abc.G @slash.slash( name="flip-pipelin", - description="Toss a pipelin to your favourite teacher and see whether it's schnel or slo" + description="Toss a pipelin to your favourite teacher and see whether it's schnel or slo", + guild_ids=slash_guild_ids ) async def flip_pipelin_slash(ctx: SlashContext): await ctx.send("Pipelin " + random.choice(['schnel', 'slo'])) +@slash.slash( + name="hallöhl", + description="Pulls any member to the special Löh room", + options=[ + create_option( + name="user", + description="The user to pull to the Löh room", + option_type=SlashCommandOptionType.USER, + required=True + ) + ], + guild_ids=slash_guild_ids +) +@slash.permission( + guild_id = INF19X_GUILD_ID, + permissions=[ + create_permission(LOEH_ID, SlashCommandPermissionType.USER, permission=True), + ], +) +async def halloehl_slash(ctx: SlashContext, user: discord.Member): + if user.voice is None: + await ctx.send("User is not is not connected to a vc", hidden=True) + return + + if user.voice.channel.guild.id != ctx.guild_id: + await ctx.send("User is not connected to this guild", hidden=True) + return + + vc: Optional[discord.VoiceChannel] = ctx.guild.get_channel(902246980124811335) + if vc is None: + await ctx.send("This command is not available in this guild", hidden=True) + return + + loeh = await _get_loeh(ctx.guild) + if loeh is None: + await ctx.send("404 - Löh not found", hidden=True) + return + + if loeh not in vc.members: + await ctx.send("You are not in your channel!", hidden=True) + return + + perms = loeh.permissions_in(user.voice.channel) + if not perms.view_channel or not perms.connect: + await ctx.send("Can't move user out of private channel", hidden=True) + return + + await user.move_to(vc, reason="Pull to Löh") + await ctx.send("done", hidden=True) + + # ____ ____ ___ _ _ ____ ____ # / ___| _ \ / _ \| | | | _ \/ ___| # | | _| |_) | | | | | | | |_) \___ \ diff --git a/lib/utils.py b/lib/utils.py index ffa2190..11b9ddf 100644 --- a/lib/utils.py +++ b/lib/utils.py @@ -1,8 +1,7 @@ import os import random import string -from collections import AsyncIterable -from typing import Callable, AsyncGenerator, Optional, Any +from typing import Callable, AsyncGenerator, AsyncIterable, Optional, Any import discord import gtts