-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from albertsgarde/21-change-role-capabilities
21 change role capabilities
- Loading branch information
Showing
13 changed files
with
397 additions
and
241 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -162,6 +162,7 @@ cython_debug/ | |
#.idea/ | ||
|
||
db*.json | ||
.bot_config.toml | ||
|
||
.vscode/ | ||
.ruff_cache/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,33 @@ | ||
# pragma: coverage exclude file | ||
import logging | ||
import os | ||
import sys | ||
import tomllib | ||
from pathlib import Path | ||
|
||
import discord | ||
from discord.abc import Snowflake | ||
|
||
from eadk_discord import bot_setup | ||
|
||
if __name__ == "__main__": | ||
logging.basicConfig(level=logging.DEBUG) | ||
|
||
bot_token_option: str | None = os.getenv("DISCORD_BOT_TOKEN") | ||
if bot_token_option is None: | ||
raise ValueError("DISCORD_BOT_TOKEN is not set in environment variables") | ||
else: | ||
bot_token: str = bot_token_option | ||
def get_config_path(env_var_name: str) -> str: | ||
match len(sys.argv): | ||
case 1: | ||
env_var_option: str | None = os.getenv(env_var_name) | ||
if env_var_option is None: | ||
raise ValueError(f"environment variable '{env_var_name}' is not set") | ||
else: | ||
return env_var_option | ||
case 2: | ||
return sys.argv[1] | ||
case num_args: | ||
raise ValueError(f"expected 0 or 1 argument, got {num_args-1}") | ||
|
||
database_path_option: str | None = os.getenv("DATABASE_PATH") | ||
if database_path_option is None: | ||
raise ValueError("DATABASE_PATH is not set in environment variables") | ||
else: | ||
database_path: Path = Path(database_path_option) | ||
|
||
guild_ids_option: str | None = os.getenv("GUILD_IDS") | ||
if guild_ids_option is None: | ||
raise ValueError("GUILD_IDS is not set in environment variables") | ||
else: | ||
guilds: list[Snowflake] = [discord.Object(id=int(guild_id)) for guild_id in guild_ids_option.split(",")] | ||
if __name__ == "__main__": | ||
logging.basicConfig(level=logging.DEBUG) | ||
|
||
config_path = Path(get_config_path("EADK_DISCORD_CONFIG_PATH")) | ||
|
||
bot = bot_setup.setup_bot(database_path, guilds) | ||
with open(config_path, "rb") as config_file: | ||
config = bot_setup.BotConfig.model_validate(tomllib.load(config_file)) | ||
|
||
bot.run(bot_token) | ||
config.run_bot() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.