Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cog handler & error logging #286

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 32 additions & 4 deletions cogs/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,33 @@
from pkgutil import walk_packages
import json
import logging

EXTENTIONS = set(
module.name for module in walk_packages(__path__, f'{__package__}.')
)
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
logger = logging.getLogger(__name__)
cogs = []
loaded_cogs = []
all_cogs = []
def load_cogs():
"""load the cogs from the cogs.json file"""
global cogs, loaded_cogs, all_cogs
try:
cogs = json.load(open("./cogs/cogs.json"))
except FileNotFoundError:
logger.error("cogs.json not found... please see if the file exists in the cogs directory.")
except json.JSONDecodeError:
logger.error("cogs.json is not a valid json file...")

for cog in cogs:
if cog['is_enabled']:
loaded_cogs.append(cog['name'])
all_cogs.append(cog['name'])
load_cogs()
def update_cogs(loaded):
"""update the cogs.json file with the loaded cogs"""
global cogs
for cog in cogs:
if cog['name'] in loaded:
cog['is_enabled'] = True
else:
cog['is_enabled'] = False
with open("./cogs/cogs.json", "w") as f:
json.dump(cogs, f, indent=4)
Loading
Loading