forked from cswimr/SeaCogs
SeaswimmerTheFsh
3c4fba46b6
- changed how the cog loads, instead of depending on the `PyLavPlayer` cog, it'll just load PyLav from the `__init__.py` file - moved configuration to a separate file - added a configuration menu - added pylav as a dependency in poetry and `info.json` - set repository python version to `>=3.11,<3.12`
68 lines
3.5 KiB
Python
68 lines
3.5 KiB
Python
from discord import ButtonStyle, Embed, Interaction, ui
|
|
from redbot.core import commands
|
|
from redbot.core.utils.chat_formatting import bold
|
|
|
|
from tts.config import config
|
|
|
|
|
|
class Menu(ui.View):
|
|
def __init__(self, ctx: commands.Context):
|
|
super().__init__()
|
|
self.ctx = ctx
|
|
|
|
@ui.button(label="Announce", style=ButtonStyle.green, row=0)
|
|
async def announce(self, interaction: Interaction, button: ui.Button):
|
|
if not interaction.user.guild_permissions.manage_guild and not interaction.user.guild_permissions.administrator:
|
|
await interaction.response.send_message("You must have the manage guild permission to change this setting.", ephemeral=True)
|
|
return
|
|
await interaction.response.defer()
|
|
current_setting = await config.guild(interaction.guild).announce
|
|
await config.guild(interaction.guild).announce.set(not current_setting)
|
|
await interaction.message.edit(embed=await embed(self.ctx))
|
|
|
|
@ui.button(label="Use Voice Channels", style=ButtonStyle.green, row=0)
|
|
async def voice_channels(self, interaction: Interaction, button: ui.Button):
|
|
if not interaction.user.guild_permissions.manage_guild and not interaction.user.guild_permissions.administrator:
|
|
await interaction.response.send_message("You must have the manage guild permission to change this setting.", ephemeral=True)
|
|
return
|
|
await interaction.response.defer()
|
|
current_setting = await config.guild(interaction.guild).voice_channels()
|
|
await config.guild(interaction.guild).voice_channels.set(not current_setting)
|
|
await interaction.message.edit(embed=await embed(self.ctx))
|
|
|
|
@ui.select(placeholder="Enabled Channels", cls=ui.ChannelSelect, row=1)
|
|
async def log_channel(self, interaction: Interaction, select: ui.ChannelSelect):
|
|
if not interaction.user.guild_permissions.manage_guild and not interaction.user.guild_permissions.administrator:
|
|
await interaction.response.send_message("You must have the manage guild permission to change this setting.", ephemeral=True)
|
|
return
|
|
await interaction.response.defer()
|
|
channels: list = await config.guild(interaction.guild).enabled_channels()
|
|
if select.values[0] in channels:
|
|
channels.remove(select.values[0])
|
|
else:
|
|
channels.append(select.values[0])
|
|
await config.guild(interaction.guild).enabled_channels.set(channels)
|
|
await interaction.message.edit(embed=await embed(self.ctx))
|
|
|
|
async def embed(ctx: commands.Context):
|
|
embed = Embed(title="TTS Settings", color=ctx.embed_color)
|
|
override_settings = {
|
|
"announce": await config.guild(ctx.guild).announce(),
|
|
"voice_channels": await config.guild(ctx.guild).voice_channels(),
|
|
"enabled_channels": await config.guild(ctx.guild).enabled_channels(),
|
|
}
|
|
|
|
override_str = [
|
|
"- " + bold("Announce: ") + get_bool_emoji(override_settings["announce"]),
|
|
"- " + bold("Voice Channels: ") + get_bool_emoji(override_settings["voice_channels"]),
|
|
"- " + ", ".join([f"<#{channel}>" for channel in override_settings["voice_channels"]])
|
|
]
|
|
embed.description = "\n".join(override_str)
|
|
|
|
def get_bool_emoji(value: bool) -> str:
|
|
"""Returns a unicode emoji based on a boolean value."""
|
|
if value is True:
|
|
return "\N{WHITE HEAVY CHECK MARK}"
|
|
if value is False:
|
|
return "\N{NO ENTRY SIGN}"
|
|
return "\N{BLACK QUESTION MARK ORNAMENT}\N{VARIATION SELECTOR-16}"
|