import discord from discord import app_commands from discord.ext import commands from discord.ui import ChannelSelect from common.logging import report from query.guild import set_output_channel class SelectOutputChannel(discord.ui.View): def __init__(self, pg): super().__init__() self.pg = pg @discord.ui.select(cls=ChannelSelect, channel_types=[discord.ChannelType.text]) async def select_channels(self, interaction: discord.Interaction, select: ChannelSelect): await set_output_channel(self.pg, interaction.guild_id, select.values[0].id) return await interaction.response.send_message(f'You selected {select.values[0].mention}') # class SelectOutputChannel(discord.ui.Select): # def __init__(self, pg, channels): # self.pg = pg # options = [] # for channel in channels: # options.append(discord.SelectOption(label=str(channel.name),emoji="👌",description=str(channel.category)),) # super().__init__(placeholder="Select an option",max_values=1,min_values=1,options=options) # async def callback(self, interaction: discord.Interaction): # await set_output_channel(self.pg, interaction.guild_id, 971796738484625468) # await interaction.response.send_message(content=f"Your choice is {self.values[0]}!", ephemeral=True) # class SelectInteract(discord.ui.Select): # def __init__(self, pg): # self.pg = pg # options = [ # discord.SelectOption(label="Option 1", emoji=":x:", description="Disabled"), # discord.SelectOption(label="Option 2", emoji=":white_square_button:", description="Defer to default"), # discord.SelectOption(label="Option 3", emoji=":white_check_mark:", description="Enabled") # ] # super().__init__(placeholder="Select an option", max_values=1, min_values=1, options=options) # async def callback(self, interaction: discord.Interaction): # await interaction.response.send_message(content=f"Your choice is {self.values[0]}!", ephemeral=True) # # class SelectGames(discord.ui.Select): # def __init__(self, pg, channels): # self.pg = pg # options = [ # discord.SelectOption(label="Option 1", emoji=":x:", description="Disabled"), # discord.SelectOption(label="Option 2", emoji=":white_square_button:", description="Defer to default"), # discord.SelectOption(label="Option 3", emoji=":white_check_mark:", description="Enabled") # ] # super().__init__(placeholder="Select an option", max_values=1, min_values=1, options=options) # async def callback(self, interaction: discord.Interaction): # await interaction.response.send_message(content=f"Your choice is {self.values[0]}!", ephemeral=True) # class SelectView(discord.ui.View): # def __init__(self, pg, channels, *, timeout = 180): # super().__init__(timeout=timeout) # self.add_item(SelectOutputChannel(pg, channels)) class Admin(commands.Cog): """Administrative functionality.""" def __init__(self, bot: commands.Bot): self.bot = bot @app_commands.command( name="guildsettings", description="Modify guild specific settings", ) @commands.has_guild_permissions(administrator=True) async def guildsettings(self, interaction: discord.Interaction): #await ctx.send("Menus!", view=SelectView(self.bot.pg, ctx.guild.channels)) await interaction.response.send_message("Menus!", view=SelectOutputChannel(self.bot.pg), ephemeral=True) @commands.command( name="sync", description="Sync commands", brief="Synchronise commands with Discord", help="Update the bot commands" ) @commands.is_owner() async def sync(self, ctx: commands.Context) -> None: synced = await ctx.bot.tree.sync() await ctx.send(f"Synced {len(synced)} commands globally") @commands.command( name="testsync", description="Sync commands", brief="Synchronise commands to this Discord", help="Update the bot commands" ) @commands.is_owner() async def testsync(self, ctx: commands.Context) -> None: ctx.bot.tree.copy_global_to(guild=ctx.guild) synced = await ctx.bot.tree.sync(guild=ctx.guild) await ctx.send(content=f"Synced {len(synced)} commands to this guild", ephemeral=True) @app_commands.command( name="status", description="Change status.", ) async def status(self, interaction: discord.Interaction, message: str) -> None: await self.bot.change_presence(activity=discord.Game(name=message)) await interaction.response.send_message(content=":white_check_mark:") await report(self.bot, f" has set my status to `{message}`.", user=interaction.user) async def setup(bot: commands.Bot): await bot.add_cog(Admin(bot))