Create requirements, config-sample, and config reader
This commit is contained in:
parent
d3f3b608d6
commit
b2efaf340e
|
|
@ -174,3 +174,5 @@ cython_debug/
|
||||||
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
||||||
#.idea/
|
#.idea/
|
||||||
|
|
||||||
|
# ---> StarfallBot
|
||||||
|
config.toml
|
||||||
|
|
@ -0,0 +1,7 @@
|
||||||
|
from starfall.config import Config
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
try:
|
||||||
|
Config.load()
|
||||||
|
except FileNotFoundError:
|
||||||
|
pass
|
||||||
|
|
@ -0,0 +1,16 @@
|
||||||
|
# == StarfallBot configuration file ==
|
||||||
|
|
||||||
|
[web]
|
||||||
|
# What port the web server uses.
|
||||||
|
port = 5000
|
||||||
|
# Connection database url.
|
||||||
|
# sqlite is only production safe to a point - consult the SQLAlchemy
|
||||||
|
# documentation to see how to set up other databases.
|
||||||
|
database_url = "sqlite:///starfallbot.db"
|
||||||
|
|
||||||
|
[discord]
|
||||||
|
token = "YOUR BOT TOKEN HERE"
|
||||||
|
|
||||||
|
[twitch]
|
||||||
|
oauth_token = "oauth:TWITCH OAUTH TOKEN"
|
||||||
|
channel = "TWITCH CHANNEL NAME"
|
||||||
|
|
@ -0,0 +1,4 @@
|
||||||
|
flask
|
||||||
|
flask-sqlalchemy
|
||||||
|
discord-py-interactions
|
||||||
|
twitchio
|
||||||
|
|
@ -0,0 +1,29 @@
|
||||||
|
import os
|
||||||
|
import tomllib
|
||||||
|
from typing import Annotated, Optional
|
||||||
|
|
||||||
|
|
||||||
|
class Config:
|
||||||
|
data: Annotated[Optional[dict],
|
||||||
|
"Configuration imported from config.toml"] = None
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def load(cls):
|
||||||
|
"""Loads the contents of the config.toml file into the class.
|
||||||
|
|
||||||
|
Raises:
|
||||||
|
FileNotFoundError: If the file does not exist.
|
||||||
|
"""
|
||||||
|
if not cls.file_exists():
|
||||||
|
raise FileNotFoundError("config.toml does not exist")
|
||||||
|
with open("config.toml", "r") as f:
|
||||||
|
cls.data = tomllib.load(f)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def file_exists(cls) -> bool:
|
||||||
|
"""Whether the config.toml file exists or needs to be created.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
bool: True if path exists and is a file, False otherwise.
|
||||||
|
"""
|
||||||
|
return os.path.exists("config.toml") and os.path.isfile("config.toml")
|
||||||
Loading…
Reference in New Issue