mirror of
https://github.com/jarulsamy/Plex-Bot.git
synced 2024-08-19 15:01:55 +02:00
allow executing outside of docker env by checking if user is root user for config path
This commit is contained in:
parent
a45ccb657e
commit
f8e5af87b6
@ -1,8 +1,6 @@
|
|||||||
"""
|
"""
|
||||||
Plex music bot for discord.
|
Plex music bot for discord.
|
||||||
|
|
||||||
Do not import this module, it is intended to be
|
|
||||||
used exclusively within a docker environment.
|
|
||||||
"""
|
"""
|
||||||
import logging
|
import logging
|
||||||
import sys
|
import sys
|
||||||
@ -19,7 +17,7 @@ plex_log = logging.getLogger("Plex")
|
|||||||
bot_log = logging.getLogger("Bot")
|
bot_log = logging.getLogger("Bot")
|
||||||
|
|
||||||
|
|
||||||
def load_config(filename: str) -> Dict[str, str]:
|
def load_config(basedir: str,filename: str) -> Dict[str, str]:
|
||||||
"""Loads config from yaml file
|
"""Loads config from yaml file
|
||||||
|
|
||||||
Grabs key/value config pairs from a file.
|
Grabs key/value config pairs from a file.
|
||||||
@ -35,12 +33,12 @@ def load_config(filename: str) -> Dict[str, str]:
|
|||||||
"""
|
"""
|
||||||
# All config files should be in /config
|
# All config files should be in /config
|
||||||
# for docker deployment.
|
# for docker deployment.
|
||||||
filename = Path("/config", filename)
|
filename = Path(basedir, filename)
|
||||||
try:
|
try:
|
||||||
with open(filename, "r") as config_file:
|
with open(filename, "r") as config_file:
|
||||||
config = yaml.safe_load(config_file)
|
config = yaml.safe_load(config_file)
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
root_log.fatal("Configuration file not found.")
|
root_log.fatal("Configuration file not found at '"+str(filename)+"'.")
|
||||||
sys.exit(-1)
|
sys.exit(-1)
|
||||||
|
|
||||||
# Convert str level type to logging constant
|
# Convert str level type to logging constant
|
||||||
|
@ -11,7 +11,11 @@ from .bot import General
|
|||||||
from .bot import Plex
|
from .bot import Plex
|
||||||
|
|
||||||
# Load config from file
|
# Load config from file
|
||||||
config = load_config("config.yaml")
|
configdir = "config"
|
||||||
|
from os import geteuid
|
||||||
|
if geteuid() == 0:
|
||||||
|
configdir = "/config"
|
||||||
|
config = load_config(configdir,"config.yaml")
|
||||||
|
|
||||||
BOT_PREFIX = config["discord"]["prefix"]
|
BOT_PREFIX = config["discord"]["prefix"]
|
||||||
TOKEN = config["discord"]["token"]
|
TOKEN = config["discord"]["token"]
|
||||||
|
Loading…
Reference in New Issue
Block a user