Skip to content

Commit

Permalink
Replace logger
Browse files Browse the repository at this point in the history
  • Loading branch information
JedHazaymeh committed Nov 11, 2023
1 parent bb61ce5 commit 4fdb638
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 143 deletions.
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ discord-typings==0.5.1
jurigged==0.5.6
discord-py-interactions==5.0.0
python-dotenv==0.19.1
loguru==0.7.2
93 changes: 0 additions & 93 deletions src/logutil.py

This file was deleted.

97 changes: 47 additions & 50 deletions src/main.py
Original file line number Diff line number Diff line change
@@ -1,55 +1,52 @@
"""
Main script to run
This script initializes extensions and starts the bot
Entrypoint script to load extensions and start the client.
"""
import os
import sys
from interactions import Activity, ActivityType, Client, listen, errors
from interactions import *
from loguru import logger
from config import DEBUG, DEV_GUILD, TOKEN
import logutil

# Configure logging for this main.py handler
logger = logutil.init_logger("main.py")
logger.debug("Debug mode is %s; You can safely ignore this.", DEBUG)

# Check if TOKEN is set
if not TOKEN:
logger.critical("TOKEN variable not set. Cannot continue")
sys.exit(1)

# Initialize the client
client = Client(
token=TOKEN,
activity=Activity(
name="Webgroup issues", type=ActivityType.WATCHING
),
debug_scope=DEV_GUILD,
auto_defer=True,
sync_ext=True,
)

# Register a listener for the startup event
@listen()
async def on_startup():
"""Called when the bot starts"""
logger.info(f"Logged in as {client.user}")

# Load built-in extensions
client.load_extension("interactions.ext.jurigged")

# Load all python files in "extensions" folder
extensions = [
f"extensions.{f[:-3]}"
for f in os.listdir("src/extensions")
if f.endswith(".py") and not f.startswith("_")
]
for extension in extensions:
try:
client.load_extension(extension)
logger.info(f"Loaded extension: {extension}")
except errors.ExtensionLoadException as e:
logger.exception(f"Failed to load extension: {extension}.", exc_info=e)

# Start the client
client.start()

if __name__ == "__main__":
if not TOKEN:
logger.critical("TOKEN environment variable not set. Exiting.")
sys.exit(1)

logger.debug("Debug mode is %s; You can safely ignore this.", DEBUG)

# Initialize the client
client = Client(
token=TOKEN,
activity=Activity(
name="Webgroup issues", type=ActivityType.WATCHING
),
debug_scope=DEV_GUILD,
auto_defer=True,
sync_ext=True,
)

# Enable built-in extensions
client.load_extension("interactions.ext.jurigged") # Hot reloading

# Load custom extensions

extensions = [
f"extensions.{f[:-3]}"
for f in os.listdir("src/extensions")
if f.endswith(".py") and not f.startswith("_")
]

for extension in extensions:
try:
client.load_extension(extension)
logger.info(f"Loaded extension: {extension}")
except errors.ExtensionLoadException as e:
logger.exception(f"Failed to load extension: {extension}", exc_info=e)

# Start the client

@listen()
async def on_startup():
logger.info(f"Logged in as {client.user}")

client.start()

0 comments on commit 4fdb638

Please sign in to comment.