mirror of
https://github.com/AsgardEternal/DiscordWhitelist.git
synced 2024-12-30 12:59:13 -06:00
refactor: use hardcoded squad perms for roles
This commit is contained in:
parent
bb61d6a3d3
commit
d1201248d1
@ -1,10 +1,14 @@
|
||||
import discord
|
||||
import logging
|
||||
from autowl import config
|
||||
from autowl.bot import Bot
|
||||
from discord.ext import commands
|
||||
from discord import app_commands
|
||||
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class Group(commands.Cog, name="group"):
|
||||
def __init__(self, client: Bot):
|
||||
self.client = client
|
||||
@ -21,96 +25,28 @@ class Group(commands.Cog, name="group"):
|
||||
)
|
||||
return
|
||||
|
||||
dropdown = discord.ui.Select(
|
||||
min_values=1,
|
||||
max_values=20,
|
||||
placeholder="Choose group permissions in Squad",
|
||||
options=[
|
||||
discord.SelectOption(
|
||||
label="changemap", description="Allows users to change the map"
|
||||
),
|
||||
discord.SelectOption(
|
||||
label="pause", description="Pause server gameplay"
|
||||
),
|
||||
discord.SelectOption(
|
||||
label="cheat", description="Use server cheat commands"
|
||||
),
|
||||
discord.SelectOption(
|
||||
label="private", description="Password protect server"
|
||||
),
|
||||
discord.SelectOption(
|
||||
label="balance", description="Group Ignores server team balance"
|
||||
),
|
||||
discord.SelectOption(
|
||||
label="chat", description="Admin chat and Server broadcast"
|
||||
),
|
||||
discord.SelectOption(
|
||||
label="kick",
|
||||
description="Allows user to kick players from the server",
|
||||
),
|
||||
discord.SelectOption(
|
||||
label="ban",
|
||||
description="Allows user to ban players from the server",
|
||||
),
|
||||
discord.SelectOption(
|
||||
label="config", description="Change server config"
|
||||
),
|
||||
discord.SelectOption(
|
||||
label="cameraman", description="Admin spectate mode"
|
||||
),
|
||||
discord.SelectOption(
|
||||
label="immune", description="Cannot be kicked / banned"
|
||||
),
|
||||
discord.SelectOption(
|
||||
label="manageserver", description="Shutdown server"
|
||||
),
|
||||
discord.SelectOption(
|
||||
label="featuretest",
|
||||
description="Any features added for testing by dev team",
|
||||
),
|
||||
discord.SelectOption(label="reserve", description="Reserve slot"),
|
||||
discord.SelectOption(
|
||||
label="demos",
|
||||
description="Record Demos on the server side via admin commands",
|
||||
),
|
||||
discord.SelectOption(
|
||||
label="clientdemos",
|
||||
description="Record Demos on the client side via commands or the replay UI.",
|
||||
),
|
||||
discord.SelectOption(
|
||||
label="debug",
|
||||
description="show admin stats command and other debugging info",
|
||||
),
|
||||
discord.SelectOption(
|
||||
label="teamchange", description="No timer limits on team change"
|
||||
),
|
||||
discord.SelectOption(
|
||||
label="forceteamchange",
|
||||
description="Can issue the ForceTeamChange command",
|
||||
),
|
||||
discord.SelectOption(
|
||||
label="canseeadminchat",
|
||||
description="This group can see the admin chat and teamkill/admin-join notifications",
|
||||
),
|
||||
],
|
||||
log.info(f"Adding {role.name} ({role.id}) as a Whitelist role")
|
||||
await interaction.response.send_message(
|
||||
f"Adding **{role.name}** as a Whitelist role"
|
||||
)
|
||||
self.client.whitelist[f"{role.name}"] = config.WhitelistGroup(
|
||||
discord_role_id=role.id, members={}
|
||||
)
|
||||
view = discord.ui.View()
|
||||
view.add_item(dropdown)
|
||||
|
||||
async def perms_handler(interaction: discord.Interaction):
|
||||
perms = "\n - ".join(dropdown.values)
|
||||
dropdown.disabled = True
|
||||
await interaction.response.edit_message(view=view)
|
||||
await interaction.followup.send(
|
||||
f"Adding **{role.name}** to whitelist with permissions:\n - {perms}\n\n"
|
||||
@app_commands.command()
|
||||
async def remove(
|
||||
self,
|
||||
interaction: discord.Interaction,
|
||||
role: discord.Role,
|
||||
):
|
||||
if not self.client.whitelist.get(role.name):
|
||||
await interaction.response.send_message(
|
||||
f"**{role.name}** has not been added as a whitelisted group, unable to remove!"
|
||||
)
|
||||
self.client.whitelist[f"{role.name}"] = config.WhitelistGroup(
|
||||
permissions=dropdown.values, discord_role_id=role.id, members={}
|
||||
)
|
||||
print(self.client.whitelist)
|
||||
return
|
||||
|
||||
dropdown.callback = perms_handler
|
||||
|
||||
ctx: commands.Context = await self.client.get_context(interaction)
|
||||
|
||||
await ctx.send(view=view)
|
||||
log.info(f"Removing {role.name} ({role.id}) from Whitelisted role")
|
||||
await interaction.response.send_message(
|
||||
f"Removed **{role.name}** from Whitelisted roles"
|
||||
)
|
||||
self.client.whitelist.pop(role.name)
|
||||
|
@ -14,7 +14,6 @@ class WhitelistMember:
|
||||
|
||||
@dataclass
|
||||
class WhitelistGroup:
|
||||
permissions: list[str]
|
||||
discord_role_id: int
|
||||
members: dict[int, WhitelistMember]
|
||||
|
||||
@ -26,9 +25,3 @@ class Whitelist:
|
||||
def __iter__(self):
|
||||
for key in self.whitelist:
|
||||
yield self.whitelist[key]
|
||||
|
||||
|
||||
@dataclass
|
||||
class PermGroup:
|
||||
group_name: str
|
||||
permissions: list[str]
|
||||
|
Loading…
Reference in New Issue
Block a user