mirror of
https://github.com/RafaelSolVargas/Vulkan.git
synced 2025-10-29 16:57:23 +00:00
Fixing error in modules import when bot runned out of the root
This commit is contained in:
@@ -1,5 +1,7 @@
|
|||||||
|
import os
|
||||||
from decouple import config
|
from decouple import config
|
||||||
from Config.Singleton import Singleton
|
from Config.Singleton import Singleton
|
||||||
|
from Config.Folder import Folder
|
||||||
|
|
||||||
|
|
||||||
class VConfigs(Singleton):
|
class VConfigs(Singleton):
|
||||||
@@ -17,7 +19,8 @@ class VConfigs(Singleton):
|
|||||||
|
|
||||||
self.CLEANER_MESSAGES_QUANT = 5
|
self.CLEANER_MESSAGES_QUANT = 5
|
||||||
self.ACQUIRE_LOCK_TIMEOUT = 10
|
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.VC_TIMEOUT = 300
|
||||||
|
|
||||||
self.MAX_PLAYLIST_LENGTH = 50
|
self.MAX_PLAYLIST_LENGTH = 50
|
||||||
|
|||||||
19
Config/Folder.py
Normal file
19
Config/Folder.py
Normal 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
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import os
|
||||||
from random import choices
|
from random import choices
|
||||||
import string
|
import string
|
||||||
from discord.bot import Bot
|
from discord.bot import Bot
|
||||||
@@ -35,13 +36,12 @@ class VulkanInitializer:
|
|||||||
def __add_cogs(self, bot: Bot) -> None:
|
def __add_cogs(self, bot: Bot) -> None:
|
||||||
try:
|
try:
|
||||||
cogsStatus = []
|
cogsStatus = []
|
||||||
for filename in listdir(f'./{self.__config.COMMANDS_PATH}'):
|
for filename in listdir(self.__config.COMMANDS_PATH):
|
||||||
if filename.endswith('.py'):
|
if filename.endswith('.py'):
|
||||||
cogPath = f'{self.__config.COMMANDS_PATH}.{filename[:-3]}'
|
cogPath = f'{self.__config.COMMANDS_FOLDER_NAME}.{filename[:-3]}'
|
||||||
cogsStatus.append(bot.load_extension(cogPath, store=True))
|
cogsStatus.append(bot.load_extension(cogPath, store=True))
|
||||||
|
|
||||||
if len(bot.cogs.keys()) != self.__getTotalCogs():
|
if len(bot.cogs.keys()) != self.__getTotalCogs():
|
||||||
print(cogsStatus)
|
|
||||||
raise VulkanError(message='Failed to load some Cog')
|
raise VulkanError(message='Failed to load some Cog')
|
||||||
|
|
||||||
except VulkanError as e:
|
except VulkanError as e:
|
||||||
@@ -49,7 +49,7 @@ class VulkanInitializer:
|
|||||||
|
|
||||||
def __getTotalCogs(self) -> int:
|
def __getTotalCogs(self) -> int:
|
||||||
quant = 0
|
quant = 0
|
||||||
for filename in listdir(f'./{self.__config.COMMANDS_PATH}'):
|
for filename in listdir(self.__config.COMMANDS_PATH):
|
||||||
if filename.endswith('.py'):
|
if filename.endswith('.py'):
|
||||||
quant += 1
|
quant += 1
|
||||||
return quant
|
return quant
|
||||||
|
|||||||
3
main.py
3
main.py
@@ -1,7 +1,8 @@
|
|||||||
from Music.VulkanInitializer import VulkanInitializer
|
from Music.VulkanInitializer import VulkanInitializer
|
||||||
|
from Config.Folder import Folder
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
folder = Folder()
|
||||||
initializer = VulkanInitializer(willListen=True)
|
initializer = VulkanInitializer(willListen=True)
|
||||||
vulkanBot = initializer.getBot()
|
vulkanBot = initializer.getBot()
|
||||||
vulkanBot.startBot()
|
vulkanBot.startBot()
|
||||||
|
|||||||
Reference in New Issue
Block a user