Skip to content

Commit

Permalink
Add /vip add and /vip remove commands
Browse files Browse the repository at this point in the history
  • Loading branch information
EthanC committed Oct 25, 2024
1 parent c8ef970 commit 3c5336f
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 3 deletions.
3 changes: 2 additions & 1 deletion config_example.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
},
"roles": {
"require": [1234567890, 9876543210],
"allow": [1324657980, 2315648970]
"allow": [1324657980, 2315648970],
"vip": 1234567890
},
"forums": {
"server": 1234567890,
Expand Down
1 change: 1 addition & 0 deletions core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def __init__(self) -> None:

self.rolesRequire: list[int] = self.values["roles"]["require"]
self.rolesAllow: list[int] = self.values["roles"]["allow"]
self.rolesVIP: int = self.values["roles"]["vip"]

self.forumsServer: int = self.values["forums"]["server"]
self.forumsLifetime: int = self.values["forums"]["lifetime"]
Expand Down
26 changes: 26 additions & 0 deletions core/sounds.py

Large diffs are not rendered by default.

87 changes: 85 additions & 2 deletions extensions/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,24 @@
Option,
SlashGroup,
StrParams,
UserParams,
)
from hikari import (
Attachment,
Bytes,
GatewayBot,
GatewayGuild,
Member,
Message,
MessageFlag,
User,
)
from hikari import Attachment, GatewayBot, Message, MessageFlag
from loguru import logger

from core.formatters import Colors, ExpandChannel, ExpandUser, Response
from core.config import Config
from core.formatters import Colors, ExpandChannel, ExpandServer, ExpandUser, Response
from core.hooks import HookError, HookLog
from core.sounds import IW7N31LDeath, T6FBIKick

plugin: GatewayPlugin = GatewayPlugin("admin")
emoji: SlashGroup[GatewayClient] = plugin.include_slash_group(
Expand All @@ -22,6 +34,9 @@
sticker: SlashGroup[GatewayClient] = plugin.include_slash_group(
"sticker", "Commands to manage server stickers."
)
vip: SlashGroup[GatewayClient] = plugin.include_slash_group(
"vip", "Commands to manage server VIPs."
)


@arc.loader
Expand Down Expand Up @@ -320,3 +335,71 @@ async def ErrorHandler(ctx: GatewayContext, error: Exception) -> None:
"""Handler for errors originating from this plugin."""

await HookError(ctx, error)


@vip.include
@arc.with_hook(arc.owner_only)
@arc.with_hook(HookLog)
@arc.slash_subcommand("add", "Add a user to the server VIP list.")
async def CommandVIPAdd(
ctx: GatewayContext,
user: Option[User, UserParams("Choose a user to add to the server VIP list.")],
) -> None:
"""Handler for the /vip add command."""

server: GatewayGuild | None = ctx.get_guild()

if not server:
raise RuntimeError(
f"guild {await ExpandServer(ctx.guild_id, format=False)} is null"
)

member: Member | None = server.get_member(user.id)

if not member:
raise RuntimeError(
f"member {await ExpandUser(user, format=False)} in guild {await ExpandServer(ctx.guild_id, format=False)} is null"
)

cfg: Config = plugin.client.get_type_dependency(Config)

await member.add_role(
cfg.rolesVIP,
reason=f"Requested by {await ExpandUser(ctx.author, format=False)}",
)

await ctx.respond(attachment=Bytes(IW7N31LDeath(), "add.mp3"))


@vip.include
@arc.with_hook(arc.owner_only)
@arc.with_hook(HookLog)
@arc.slash_subcommand("remove", "Remove a user from the server VIP list.")
async def CommandVIPRemove(
ctx: GatewayContext,
user: Option[User, UserParams("Choose a user to remove from the server VIP list.")],
) -> None:
"""Handler for the /vip remove command."""

server: GatewayGuild | None = ctx.get_guild()

if not server:
raise RuntimeError(
f"guild {await ExpandServer(ctx.guild_id, format=False)} is null"
)

member: Member | None = server.get_member(user.id)

if not member:
raise RuntimeError(
f"member {await ExpandUser(user, format=False)} in guild {await ExpandServer(ctx.guild_id, format=False)} is null"
)

cfg: Config = plugin.client.get_type_dependency(Config)

await member.remove_role(
cfg.rolesVIP,
reason=f"Requested by {await ExpandUser(ctx.author, format=False)}",
)

await ctx.respond(attachment=Bytes(T6FBIKick(), "kick.mp3"))

0 comments on commit 3c5336f

Please sign in to comment.