tux.database.controllers.guild_config
¶
Classes:
Name | Description |
---|---|
GuildConfigController | |
Classes¶
GuildConfigController()
¶
Initialize the controller with database tables.
Methods:
Name | Description |
---|---|
ensure_guild_exists | Ensure the guild exists in the database. |
insert_guild_config | Insert a new guild config into the database. |
get_guild_config | Get a guild config from the database. |
get_guild_prefix | Get a guild prefix from the database. |
get_perm_level_role | Get the role id for a specific permission level. |
get_perm_level_roles | Get the role ids for all permission levels from the lower_bound up to but not including 8. |
Source code in tux/database/controllers/guild_config.py
Functions¶
ensure_guild_exists(guild_id: int) -> Any
async
¶
Ensure the guild exists in the database.
Source code in tux/database/controllers/guild_config.py
insert_guild_config(guild_id: int) -> Any
async
¶
Insert a new guild config into the database.
get_guild_config(guild_id: int) -> Any
async
¶
get_guild_prefix(guild_id: int) -> str | None
async
¶
Get a guild prefix from the database.
get_perm_level_role(guild_id: int, level: str) -> int | None
async
¶
Get the role id for a specific permission level.
Source code in tux/database/controllers/guild_config.py
Python
async def get_perm_level_role(self, guild_id: int, level: str) -> int | None:
"""
Get the role id for a specific permission level.
"""
try:
role_id = await self.get_guild_config_field_value(guild_id, level) # type: ignore
logger.debug(f"Retrieved role_id {role_id} for guild {guild_id} and level {level}")
except Exception as e:
logger.error(f"Error getting perm level role: {e}")
return None
return role_id
get_perm_level_roles(guild_id: int, lower_bound: int) -> list[int] | None
async
¶
Get the role ids for all permission levels from the lower_bound up to but not including 8.
Source code in tux/database/controllers/guild_config.py
Python
async def get_perm_level_roles(self, guild_id: int, lower_bound: int) -> list[int] | None:
"""
Get the role ids for all permission levels from the lower_bound up to but not including 8.
"""
perm_level_roles: dict[int, str] = {
0: "perm_level_0_role_id",
1: "perm_level_1_role_id",
2: "perm_level_2_role_id",
3: "perm_level_3_role_id",
4: "perm_level_4_role_id",
5: "perm_level_5_role_id",
6: "perm_level_6_role_id",
7: "perm_level_7_role_id",
}
try:
role_ids: list[int] = []
for level in range(lower_bound, 8):
if role_field := perm_level_roles.get(level):
role_id = await self.get_guild_config_field_value(guild_id, role_field) # type: ignore
if role_id:
role_ids.append(role_id)
logger.debug(f"Retrieved role_ids {role_ids} for guild {guild_id} with lower bound {lower_bound}")
except Exception as e:
logger.error(f"Error getting perm level roles: {e}")
return None
return role_ids