1
0

admin.py 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import discord
  2. #import secrets
  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. async def setup(bot: commands.Bot):
  9. await bot.add_cog(Admin(bot))
  10. class View(discord.ui.View):
  11. def __init__(self, pg):
  12. super().__init__()
  13. self.pg = pg
  14. @discord.ui.select(cls=ChannelSelect, channel_types=[discord.ChannelType.text])
  15. async def select_channels(self, interaction: discord.Interaction, select: ChannelSelect):
  16. await set_output_channel(self.pg, interaction.guild_id, select.values[0].id)
  17. return await interaction.response.send_message(f'You selected {select.values[0].mention}')
  18. class Select(discord.ui.Select):
  19. def __init__(self, pg, channels):
  20. self.pg = pg
  21. print(channels)
  22. options = []
  23. for channel in channels:
  24. options.append(discord.SelectOption(label=str(channel.name),emoji="👌",description=str(channel.category)),)
  25. print(options)
  26. #options=[
  27. # discord.SelectOption(label="Option 1",emoji="👌",description="This is option 1!"),
  28. # discord.SelectOption(label="Option 2",emoji="✨",description="This is option 2!"),
  29. # discord.SelectOption(label="Option 3",emoji="🎭",description="This is option 3!")
  30. # ]
  31. super().__init__(placeholder="Select an option",max_values=1,min_values=1,options=options)
  32. async def callback(self, interaction: discord.Interaction):
  33. await set_output_channel(self.pg, interaction.guild_id, 971796738484625468)
  34. await interaction.response.send_message(content=f"Your choice is {self.values[0]}!", ephemeral=True)
  35. class SelectView(discord.ui.View):
  36. def __init__(self, pg, channels, *, timeout = 180):
  37. super().__init__(timeout=timeout)
  38. self.add_item(Select(pg, channels))
  39. class Admin(commands.Cog):
  40. """Administrative functionality."""
  41. def __init__(self, bot: commands.Bot):
  42. self.bot = bot
  43. # @commands.command(
  44. # description="Modify channel settings via a browser",
  45. # brief="Set channel specific settings via the webgui",
  46. # help="Sends a single-use time based token to the webportal"
  47. # )
  48. # #@commands.has_guild_permissions(administrator=True)
  49. # async def guildsettings(self, ctx: commands.Context):
  50. #
  51. # # Halt on ignore list.
  52. # if await check_ignore(self.bot.pg, ctx.author):
  53. # return
  54. #
  55. # #await ctx.send("Menus!", view=SelectView(self.bot.pg, ctx.guild.channels))
  56. # await ctx.send("Menus!", view=View(self.bot.pg), ephemeral=True)