Constants Singleton¶
Defines constants used across multiple files in this project. Most of these constants are loaded from the environment variables This singleton also holds parsed arguments
-
class
constants.Constants(args)¶ Bases:
objectSingleton accesible via GetConstants Below is the list of the variables you can access via the getter for this singleton
- Variables
BOT_TOKEN (str) – The API token for the bot
GUILD_ID (int) – The ID for the server which the bot will be serving
WAITING_ROOM_CHANNEL_ID (str) – Channel ID of the waiting room
QUEUE_CHANNEL_ID (int) – Channel ID of the queue
ANNOUNCMENT_CHANNEL_ID (int) – Channel ID of the announcement channel
ADMIN (str) – Name for the admin role
INSTRUCTOR_ROLE_ID (int) – Role ID for users that have the role of admin
STUDENT (str) – Name for the student role
STUDENT_ROLE_ID (int) – Role ID for users that have the role of student
CLASS (str) – The name of the class that the bot is serving
COMMAND_CHAR (str) – The character used to envoke commands, i.e. “/eq” where “/” is the command character
HELP_MESSAGES (str) – The path to the YAML file which contains the various help messages
MESSAGE_LIFETIME (str) – How long after sending the bot’s DM’s to users persist
LOGGING_DIR (str) – The path to the directory where log files will be put in
LOGGING_CAPACITY (str) – Maximum number of log files allowed in logging directory. If this amount is surpassed, then the oldest log file will be deleted
SMTP_HOST (str) – The smtp server used to send email notifications of fatal errors
MAILING_LIST (List[str]) – List of email addresses to send critical alerts too
USERNAME (str) – The email address that said notififcations will be sent form
PASSWORD (str) – The password to the aforementioned email account
Note that the above two should both specified in the .env file
-
instance: Optional[Constants] = None¶
-
constants.GetConstants()¶ Function meant to access the instance of the singleton safely. Always use this after the singleton has been initialize
- Raises
RuntimeError – Raised when the singleton has not first been instantiated
- Returns
The instance of the singleton
-
constants.parse_config(path=None, data=None, tag='!ENV')¶ Load a yaml configuration file and resolve any environment variables The environment variables must have !ENV before them and be in this format to be parsed: ${VAR_NAME}.
- How to Use the !ENV directive in your config file
database: host: !ENV ${HOST} port: !ENV ${PORT} app: log_path: !ENV '/var/${LOG_PATH}' something_else: !ENV '${AWESOME_ENV_VAR}/var/${A_SECOND_AWESOME_VAR}'
- Parameters
path (str) – the path to the yaml file
data (str) – the yaml data itself as a stream
tag (str) – the tag to look for
- Returns
the dict configuration
- Return type
dict[str, T]