Skip to content

Commit

Permalink
Refactor config
Browse files Browse the repository at this point in the history
  • Loading branch information
novanai committed Jan 14, 2025
1 parent 833a99e commit 5a00714
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 13 deletions.
5 changes: 0 additions & 5 deletions src/bot.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import logging
import sys

import arc
import hikari
Expand All @@ -8,10 +7,6 @@

from src.config import DEBUG, TOKEN

if TOKEN is None:
print("TOKEN environment variable not set. Exiting.")
sys.exit(1)

bot = hikari.GatewayBot(
token=TOKEN,
banner=None,
Expand Down
27 changes: 23 additions & 4 deletions src/config.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
import os
import sys

from dotenv import load_dotenv

load_dotenv()

TOKEN = os.environ.get("TOKEN") # required

def get_required_var(var: str) -> str:
env = os.environ.get(var)

if env is None:
print(f"{var} environment variable not set. Exiting.")
sys.exit(1)

return env


TOKEN = get_required_var("TOKEN") # required
DEBUG = os.environ.get("DEBUG", False)
DISCORD_UID_MAP = os.environ.get("DISCORD_UID_MAP")
DISCORD_UID_MAP = get_required_var("DISCORD_UID_MAP")

CHANNEL_IDS: dict[str, int] = {
"lobby": 627542044390457350,
Expand All @@ -26,7 +38,14 @@
"helpdesk": 1194683307921772594,
}

ASSIGNABLE_ROLES: dict[str, int] = {
"webgroup": 1166751688598761583,
"gamez": 1089204642241581139,
"croomer": 1172696659097047050,
"external events": 1299487948206768138,
}

UID_MAPS = dict(item.split("=") for item in DISCORD_UID_MAP.split(","))

LDAP_USERNAME = os.environ.get("LDAP_USERNAME")
LDAP_PASSWORD = os.environ.get("LDAP_PASSWORD")
LDAP_USERNAME = get_required_var("LDAP_USERNAME")
LDAP_PASSWORD = get_required_var("LDAP_PASSWORD")
10 changes: 6 additions & 4 deletions src/extensions/user_roles.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@

from src.utils import role_mention

from src.config import ASSIGNABLE_ROLES

plugin = arc.GatewayPlugin(name="User Roles")

role = plugin.include_slash_group("role", "Get/remove assignable roles.")

role_choices = [
hikari.CommandChoice(name="Webgroup", value="1166751688598761583"),
hikari.CommandChoice(name="Gamez", value="1089204642241581139"),
hikari.CommandChoice(name="Croomer", value="1172696659097047050"),
hikari.CommandChoice(name="External Events", value="1299487948206768138"),
hikari.CommandChoice(name=name.title(), value=str(value))
for name, value in ASSIGNABLE_ROLES.items()
]


Expand All @@ -21,6 +21,7 @@ async def add_role(
ctx: arc.GatewayContext,
role: arc.Option[str, arc.StrParams("The role to add.", choices=role_choices)],
) -> None:
# commands are not available in DMs, so guild_id and member will always be available
assert ctx.guild_id
assert ctx.member

Expand All @@ -46,6 +47,7 @@ async def remove_role(
ctx: arc.GatewayContext,
role: arc.Option[str, arc.StrParams("The role to remove.", choices=role_choices)],
) -> None:
# commands are not available in DMs, so guild_id and member will always be available
assert ctx.guild_id
assert ctx.member

Expand Down

0 comments on commit 5a00714

Please sign in to comment.