1
0

admin.py 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. import discord
  2. from discord import app_commands
  3. from discord.ext import commands
  4. from discord.ui import ChannelSelect
  5. #from common.logging import report
  6. from common.settings import check_ignore
  7. from query.guild import set_output_channel
  8. class View(discord.ui.View):
  9. def __init__(self, pg):
  10. super().__init__()
  11. self.pg = pg
  12. @discord.ui.select(cls=ChannelSelect, channel_types=[discord.ChannelType.text])
  13. async def select_channels(self, interaction: discord.Interaction, select: ChannelSelect):
  14. await set_output_channel(self.pg, interaction.guild_id, select.values[0].id)
  15. return await interaction.response.send_message(f'You selected {select.values[0].mention}')
  16. class Select(discord.ui.Select):
  17. def __init__(self, pg, channels):
  18. self.pg = pg
  19. print(channels)
  20. options = []
  21. for channel in channels:
  22. options.append(discord.SelectOption(label=str(channel.name),emoji="👌",description=str(channel.category)),)
  23. print(options)
  24. #options=[
  25. # discord.SelectOption(label="Option 1",emoji="👌",description="This is option 1!"),
  26. # discord.SelectOption(label="Option 2",emoji="✨",description="This is option 2!"),
  27. # discord.SelectOption(label="Option 3",emoji="🎭",description="This is option 3!")
  28. # ]
  29. super().__init__(placeholder="Select an option",max_values=1,min_values=1,options=options)
  30. async def callback(self, interaction: discord.Interaction):
  31. await set_output_channel(self.pg, interaction.guild_id, 971796738484625468)
  32. await interaction.response.send_message(content=f"Your choice is {self.values[0]}!", ephemeral=True)
  33. class SelectView(discord.ui.View):
  34. def __init__(self, pg, channels, *, timeout = 180):
  35. super().__init__(timeout=timeout)
  36. self.add_item(Select(pg, channels))
  37. class Admin(commands.Cog):
  38. """Administrative functionality."""
  39. def __init__(self, bot: commands.Bot):
  40. self.bot = bot
  41. @app_commands.command(
  42. name="guildsettings",
  43. description="Modify channel settings via a browser",
  44. #brief="Set channel specific settings via the webgui",
  45. #help="Sends a single-use time based token to the webportal"
  46. )
  47. #@commands.has_guild_permissions(administrator=True)
  48. #@commands.is_owner()
  49. async def guildsettings(self, interaction: discord.Interaction):
  50. # Halt on ignore list.
  51. if await check_ignore(self.bot.pg, ctx.author):
  52. return
  53. #await ctx.send("Menus!", view=SelectView(self.bot.pg, ctx.guild.channels))
  54. await interaction.response.send_message("Menus!", view=View(self.bot.pg), ephemeral=True)
  55. @commands.command(
  56. name="sync",
  57. description="Sync commands",
  58. brief="Synchronise commands with Discord",
  59. help="Update the bot commands"
  60. )
  61. @commands.is_owner()
  62. #async def sync(self, ctx: commands.Context):
  63. async def sync(self, ctx: commands.Context):
  64. print(self.bot.tree.get_commands())
  65. print(self.bot.tree.fetch_commands())
  66. guild_count = 0
  67. for guild in self.bot.guilds:
  68. fmt = await ctx.bot.tree.sync(guild=guild)
  69. guild_count += 1
  70. await ctx.send(content=f"Synced tree of {len(fmt)} commands to {guild_count}/{len(self.bot.guilds)} guilds", ephemeral=True)
  71. async def setup(bot: commands.Bot):
  72. await bot.add_cog(Admin(bot))