Fixing error in modules import when bot runned out of the root

This commit is contained in:
Rafael Vargas
2022-07-31 19:03:41 -04:00
parent a9cfaf62a4
commit 5b61947904
4 changed files with 29 additions and 6 deletions

View File

@@ -1,5 +1,7 @@
import os
from decouple import config
from Config.Singleton import Singleton
from Config.Folder import Folder
class VConfigs(Singleton):
@@ -17,7 +19,8 @@ class VConfigs(Singleton):
self.CLEANER_MESSAGES_QUANT = 5
self.ACQUIRE_LOCK_TIMEOUT = 10
self.COMMANDS_PATH = 'DiscordCogs'
self.COMMANDS_FOLDER_NAME = 'DiscordCogs'
self.COMMANDS_PATH = f'{Folder().rootFolder}{self.COMMANDS_FOLDER_NAME}'
self.VC_TIMEOUT = 300
self.MAX_PLAYLIST_LENGTH = 50

19
Config/Folder.py Normal file
View File

@@ -0,0 +1,19 @@
import os
from Config.Singleton import Singleton
class Folder(Singleton):
def __init__(self) -> None:
if not self.created:
filePath = os.path.dirname(__file__)
self.rootFolder = self.__getRootFolder(filePath)
def __getRootFolder(self, current: str) -> str:
last_sep_index = -1
for x in range(len(current) - 1, -1, -1):
if current[x] == os.sep:
last_sep_index = x
break
path = current[:last_sep_index] + os.sep
return path