2024-05-03 22:20:53 -04:00
|
|
|
from discord import ButtonStyle, Interaction, Message, ui
|
2024-01-16 09:02:10 -05:00
|
|
|
from redbot.core import commands
|
|
|
|
|
2024-05-06 21:39:43 -04:00
|
|
|
from ..utilities.config import config
|
|
|
|
from ..utilities.factory import guild_embed
|
|
|
|
from ..utilities.utils import create_pagesize_options
|
2024-02-14 11:04:26 -05:00
|
|
|
|
|
|
|
|
2024-01-16 09:02:10 -05:00
|
|
|
class Guild(ui.View):
|
2024-05-06 21:04:08 -04:00
|
|
|
def __init__(self, ctx: commands.Context, message: Message, timeout: int | None = None):
|
2024-01-16 09:02:10 -05:00
|
|
|
super().__init__()
|
|
|
|
self.ctx = ctx
|
2024-05-03 22:20:53 -04:00
|
|
|
self.message = message
|
|
|
|
self.timeout = timeout
|
|
|
|
|
|
|
|
async def on_timeout(self):
|
|
|
|
await self.message.edit(view=None)
|
2024-01-16 09:02:10 -05:00
|
|
|
|
|
|
|
@ui.button(label="Show Moderator", style=ButtonStyle.green, row=0)
|
2024-02-28 10:56:13 -05:00
|
|
|
async def show_moderator(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument
|
2024-01-16 09:02:10 -05:00
|
|
|
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()
|
2024-04-26 16:14:30 -04:00
|
|
|
current_setting = await config.guild(interaction.guild).show_moderator()
|
2024-01-16 09:03:58 -05:00
|
|
|
await config.guild(interaction.guild).show_moderator.set(not current_setting)
|
2024-01-16 09:26:54 -05:00
|
|
|
await interaction.message.edit(embed=await guild_embed(self.ctx))
|
2024-01-16 09:02:10 -05:00
|
|
|
|
|
|
|
@ui.button(label="Use Discord Permissions", style=ButtonStyle.green, row=0)
|
2024-02-28 10:56:13 -05:00
|
|
|
async def use_discord_permissions(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument
|
2024-01-16 09:02:10 -05:00
|
|
|
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).use_discord_permissions()
|
|
|
|
await config.guild(interaction.guild).use_discord_permissions.set(not current_setting)
|
2024-01-16 09:26:54 -05:00
|
|
|
await interaction.message.edit(embed=await guild_embed(self.ctx))
|
2024-01-16 09:02:10 -05:00
|
|
|
|
2024-04-05 10:43:58 -04:00
|
|
|
@ui.button(label="Respect Hierarchy", style=ButtonStyle.green, row=0)
|
|
|
|
async def respect_heirarchy(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument
|
|
|
|
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).respect_hierarchy()
|
|
|
|
await config.guild(interaction.guild).respect_hierarchy.set(not current_setting)
|
|
|
|
await interaction.message.edit(embed=await guild_embed(self.ctx))
|
|
|
|
|
2024-01-16 09:02:10 -05:00
|
|
|
@ui.button(label="Ignore Modlog", style=ButtonStyle.green, row=0)
|
2024-02-28 10:56:13 -05:00
|
|
|
async def ignore_modlog(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument
|
2024-01-16 09:02:10 -05:00
|
|
|
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).ignore_modlog()
|
|
|
|
await config.guild(interaction.guild).ignore_modlog.set(not current_setting)
|
2024-01-16 09:26:54 -05:00
|
|
|
await interaction.message.edit(embed=await guild_embed(self.ctx))
|
2024-01-16 09:02:10 -05:00
|
|
|
|
|
|
|
@ui.button(label="Ignore Other Bots", style=ButtonStyle.green, row=0)
|
2024-02-28 10:56:13 -05:00
|
|
|
async def ignore_other_bots(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument
|
2024-01-16 09:02:10 -05:00
|
|
|
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).ignore_other_bots()
|
|
|
|
await config.guild(interaction.guild).ignore_other_bots.set(not current_setting)
|
2024-01-16 09:26:54 -05:00
|
|
|
await interaction.message.edit(embed=await guild_embed(self.ctx))
|
2024-01-16 09:02:10 -05:00
|
|
|
|
2024-01-16 09:03:58 -05:00
|
|
|
@ui.button(label="DM Users", style=ButtonStyle.green, row=1)
|
2024-02-28 10:56:13 -05:00
|
|
|
async def dm_users(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument
|
2024-01-16 09:02:10 -05:00
|
|
|
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).dm_users()
|
|
|
|
await config.guild(interaction.guild).dm_users.set(not current_setting)
|
2024-01-16 09:26:54 -05:00
|
|
|
await interaction.message.edit(embed=await guild_embed(self.ctx))
|
2024-01-16 09:02:10 -05:00
|
|
|
|
2024-01-16 09:03:58 -05:00
|
|
|
@ui.button(label="Auto Evidence Format", style=ButtonStyle.green, row=1)
|
2024-02-28 10:56:13 -05:00
|
|
|
async def auto_evidenceformat(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument
|
2024-01-16 09:02:10 -05:00
|
|
|
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).auto_evidenceformat()
|
|
|
|
await config.guild(interaction.guild).auto_evidenceformat.set(not current_setting)
|
2024-01-16 09:26:54 -05:00
|
|
|
await interaction.message.edit(embed=await guild_embed(self.ctx))
|
2024-01-16 09:02:10 -05:00
|
|
|
|
2024-01-16 09:03:58 -05:00
|
|
|
@ui.button(label="Ephemeral", style=ButtonStyle.green, row=1)
|
2024-02-28 10:56:13 -05:00
|
|
|
async def ephemeral(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument
|
2024-01-16 09:02:10 -05:00
|
|
|
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).history_ephemeral()
|
|
|
|
await config.guild(interaction.guild).history_ephemeral.set(not current_setting)
|
2024-01-16 09:26:54 -05:00
|
|
|
await interaction.message.edit(embed=await guild_embed(self.ctx))
|
2024-01-16 09:02:10 -05:00
|
|
|
|
2024-01-16 09:03:58 -05:00
|
|
|
@ui.button(label="History Inline", style=ButtonStyle.green, row=1)
|
2024-02-28 10:56:13 -05:00
|
|
|
async def inline(self, interaction: Interaction, button: ui.Button): # pylint: disable=unused-argument
|
2024-01-16 09:02:10 -05:00
|
|
|
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).history_inline()
|
|
|
|
await config.guild(interaction.guild).history_inline.set(not current_setting)
|
2024-01-16 09:26:54 -05:00
|
|
|
await interaction.message.edit(embed=await guild_embed(self.ctx))
|
2024-01-16 09:02:10 -05:00
|
|
|
|
2024-01-16 09:06:50 -05:00
|
|
|
@ui.select(placeholder="History Pagesize", options=create_pagesize_options(), row=2)
|
2024-01-16 09:02:10 -05:00
|
|
|
async def pagesize(self, interaction: Interaction, select: ui.Select,):
|
|
|
|
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
|
|
|
|
if select.values[0] == "default":
|
|
|
|
await config.guild(interaction.guild).history_pagesize.clear()
|
|
|
|
else:
|
|
|
|
await config.guild(interaction.guild).history_pagesize.set(int(select.values[0]))
|
|
|
|
await interaction.response.defer()
|
2024-01-16 09:26:54 -05:00
|
|
|
await interaction.message.edit(embed=await guild_embed(self.ctx))
|
2024-01-16 09:02:10 -05:00
|
|
|
|
2024-01-16 09:06:50 -05:00
|
|
|
@ui.select(placeholder="History Inline Pagesize", options=create_pagesize_options(), row=3)
|
2024-01-16 09:02:10 -05:00
|
|
|
async def inline_pagesize(self, interaction: Interaction, select: ui.Select,):
|
|
|
|
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
|
|
|
|
if select.values[0] == "default":
|
|
|
|
await config.guild(interaction.guild).history_inline_pagesize.clear()
|
|
|
|
else:
|
|
|
|
await config.guild(interaction.guild).history_inline_pagesize.set(int(select.values[0]))
|
|
|
|
await interaction.response.defer()
|
2024-01-16 09:26:54 -05:00
|
|
|
await interaction.message.edit(embed=await guild_embed(self.ctx))
|
2024-01-16 09:06:50 -05:00
|
|
|
|
|
|
|
@ui.select(placeholder="Log Channel", cls=ui.ChannelSelect, row=4)
|
|
|
|
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()
|
|
|
|
await config.guild(interaction.guild).log_channel.set(select.values[0].id)
|
2024-01-16 09:26:54 -05:00
|
|
|
await interaction.message.edit(embed=await guild_embed(self.ctx))
|