testing cog
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -2,5 +2,5 @@
|
|||||||
/audio/*/
|
/audio/*/
|
||||||
/test2.py
|
/test2.py
|
||||||
/user.db
|
/user.db
|
||||||
/*.json
|
*.json
|
||||||
*.pyc
|
*.pyc
|
||||||
|
|||||||
68
test.py
68
test.py
@@ -11,6 +11,8 @@ from discord.ext import commands
|
|||||||
from dislash import InteractionClient, Option, OptionType
|
from dislash import InteractionClient, Option, OptionType
|
||||||
|
|
||||||
|
|
||||||
|
bot_owner = 386629192743256065
|
||||||
|
|
||||||
class DB:
|
class DB:
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _prepare_db(guild: int):
|
def _prepare_db(guild: int):
|
||||||
@@ -65,6 +67,50 @@ class DB:
|
|||||||
logging.error("Failed to read sqlite table", error)
|
logging.error("Failed to read sqlite table", error)
|
||||||
|
|
||||||
|
|
||||||
|
class Cogs_prepare:
|
||||||
|
@staticmethod
|
||||||
|
def _cog_list():
|
||||||
|
cogs_list = []
|
||||||
|
for filename in listdir('./cogs'):
|
||||||
|
if filename.endswith('.py'):
|
||||||
|
cogs_list.append(filename[:-3])
|
||||||
|
return cogs_list
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
async def _cogs_load(ctx):
|
||||||
|
for filename in Cogs_prepare._cog_list():
|
||||||
|
if filename.endswith('.py'):
|
||||||
|
bot.load_extension(f'cogs.{filename[:-3]}')
|
||||||
|
print(f'Load cog {filename[:-3]}')
|
||||||
|
else:
|
||||||
|
print(f'Unable to load {filename[:-3]}')
|
||||||
|
|
||||||
|
await ctx.reply('Cogs loaded')
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
async def _cogs_unload(ctx):
|
||||||
|
for filename in Cogs_prepare._cog_list():
|
||||||
|
bot.unload_extension(f'cogs.{filename[:-3]}')
|
||||||
|
print(f'Unload cog {filename[:-3]}')
|
||||||
|
|
||||||
|
await ctx.reply('Cogs unloaded')
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
async def _cog_load(ctx, cog):
|
||||||
|
try:
|
||||||
|
bot.load_extension(f'cogs.{cog}')
|
||||||
|
await ctx.reply(f'Loaded cog {cog}')
|
||||||
|
|
||||||
|
except commands.ExtensionNotFound:
|
||||||
|
await ctx.send(f"Error: {cog} couldn't be found to load.")
|
||||||
|
|
||||||
|
except commands.ExtensionFailed:
|
||||||
|
await ctx.send(f'Error: {cog} failed to load properly.')
|
||||||
|
|
||||||
|
except commands.ExtensionError:
|
||||||
|
await ctx.send(f'Error: unknown error with {cog}')
|
||||||
|
|
||||||
|
|
||||||
threading.current_thread().name = "main"
|
threading.current_thread().name = "main"
|
||||||
logging.basicConfig(stream=sys.stdout, filemode='w', level='INFO',
|
logging.basicConfig(stream=sys.stdout, filemode='w', level='INFO',
|
||||||
format='%(asctime)s - %(levelname)s - %(threadName)s - %(message)s')
|
format='%(asctime)s - %(levelname)s - %(threadName)s - %(message)s')
|
||||||
@@ -88,12 +134,22 @@ intents.members = True
|
|||||||
bot = commands.Bot(command_prefix=determine_prefix, guild_subscriptions=True, intents=intents)
|
bot = commands.Bot(command_prefix=determine_prefix, guild_subscriptions=True, intents=intents)
|
||||||
inter_client = InteractionClient(bot)
|
inter_client = InteractionClient(bot)
|
||||||
|
|
||||||
for filename in listdir('./cogs'):
|
|
||||||
if filename.endswith('.py'):
|
print(Cogs_prepare._cog_list())
|
||||||
bot.load_extension(f'cogs.{filename[:-3]}')
|
|
||||||
print(f'Load cog {filename[:-3]}')
|
for filename in Cogs_prepare._cog_list():
|
||||||
else:
|
try:
|
||||||
print(f'Unable to load {filename[:-3]}')
|
bot.load_extension(f'cogs.{filename}')
|
||||||
|
logging.info(f'Loaded cog {filename}')
|
||||||
|
|
||||||
|
except commands.ExtensionNotFound:
|
||||||
|
logging.error(f"Error: {filename} couldn't be found to load.")
|
||||||
|
|
||||||
|
except commands.ExtensionFailed:
|
||||||
|
logging.error(f'Error: {filename} failed to load properly.')
|
||||||
|
|
||||||
|
except commands.ExtensionError:
|
||||||
|
logging.error(f'Error: unknown error with {filename[:-3]}')
|
||||||
|
|
||||||
|
|
||||||
class Commands:
|
class Commands:
|
||||||
|
|||||||
Reference in New Issue
Block a user