| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- import discord
- from discord import app_commands
- from discord.ext import commands
- from discord.ui import ChannelSelect
- #from common.logging import report
- from common.settings import check_ignore
- from query.guild import set_output_channel
- class View(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 Select(discord.ui.Select):
- def __init__(self, pg, channels):
- self.pg = pg
- print(channels)
- options = []
- for channel in channels:
- options.append(discord.SelectOption(label=str(channel.name),emoji="👌",description=str(channel.category)),)
- print(options)
- #options=[
- # discord.SelectOption(label="Option 1",emoji="👌",description="This is option 1!"),
- # discord.SelectOption(label="Option 2",emoji="✨",description="This is option 2!"),
- # discord.SelectOption(label="Option 3",emoji="🎭",description="This is option 3!")
- # ]
- 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 SelectView(discord.ui.View):
- def __init__(self, pg, channels, *, timeout = 180):
- super().__init__(timeout=timeout)
- self.add_item(Select(pg, channels))
- class Admin(commands.Cog):
- """Administrative functionality."""
- def __init__(self, bot: commands.Bot):
- self.bot = bot
- @app_commands.command(
- name="guildsettings",
- description="Modify channel settings via a browser",
- #brief="Set channel specific settings via the webgui",
- #help="Sends a single-use time based token to the webportal"
- )
- #@commands.has_guild_permissions(administrator=True)
- #@commands.is_owner()
- async def guildsettings(self, interaction: discord.Interaction):
- # Halt on ignore list.
- if await check_ignore(self.bot.pg, ctx.author):
- return
- #await ctx.send("Menus!", view=SelectView(self.bot.pg, ctx.guild.channels))
- await interaction.response.send_message("Menus!", view=View(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):
- async def sync(self, ctx: commands.Context):
- print(self.bot.tree.get_commands())
- print(self.bot.tree.fetch_commands())
- guild_count = 0
- for guild in self.bot.guilds:
- fmt = await ctx.bot.tree.sync(guild=guild)
- guild_count += 1
- await ctx.send(content=f"Synced tree of {len(fmt)} commands to {guild_count}/{len(self.bot.guilds)} guilds", ephemeral=True)
- async def setup(bot: commands.Bot):
- await bot.add_cog(Admin(bot))
|