Update template to be more python-module like.

This commit is contained in:
2025-03-19 08:44:51 -04:00
parent 582ec6a5f0
commit 6f65ae0d91
4 changed files with 21 additions and 19 deletions
+14
View File
@@ -0,0 +1,14 @@
"""Starts the app for off_cooldown_bot."""
import logging
from .app import run
nextcord_logger = logging.getLogger("nextcord")
nextcord_logger.setLevel(logging.DEBUG)
nextcord_handler = logging.FileHandler(filename="nextcord.log", encoding="utf-8", mode="w")
nextcord_handler.setFormatter(logging.Formatter("%(asctime)s:%(levelname)s:%(name)s: %(message)s"))
nextcord_logger.addHandler(nextcord_handler)
if __name__ == "__main__":
run()
@@ -1,6 +1,5 @@
"""Main file for bot."""
import logging
import os
import nextcord
@@ -8,14 +7,8 @@ from nextcord.ext import commands
from .settings import settings
nextcord_logger = logging.getLogger("nextcord")
nextcord_logger.setLevel(logging.DEBUG)
nextcord_handler = logging.FileHandler(filename="nextcord.log", encoding="utf-8", mode="w")
nextcord_handler.setFormatter(logging.Formatter("%(asctime)s:%(levelname)s:%(name)s: %(message)s"))
nextcord_logger.addHandler(nextcord_handler)
def main() -> None:
def run() -> None:
"""Set config, intents, then connects the bot to discord."""
# Allows privileged intents for monitoring members joining, roles editing, and role assignments
# These need to be enabled in the developer portal as well
@@ -33,8 +26,8 @@ def main() -> None:
bot = commands.Bot(intents=intents)
# Get the modules of all cogs whose directory structure is ./cogs/<module_name>
for folder in os.listdir("cogs"):
bot.load_extension(f"cogs.{folder}")
for folder in os.listdir(f"${REPO_NAME_SNAKE}/cogs"):
bot.load_extension(f"${REPO_NAME_SNAKE}.cogs.{folder}")
@bot.listen()
async def on_ready() -> None:
@@ -46,7 +39,3 @@ def main() -> None:
# Run Discord bot
bot.run(settings.params.discord_token)
if __name__ == "__main__":
main()
+3 -4
View File
@@ -8,9 +8,8 @@
"name": "Python: Module",
"type": "debugpy",
"request": "launch",
"module": "main",
"justMyCode": true,
"cwd": "$${workspaceFolder}/${REPO_NAME_SNAKE}"
"module": "${REPO_NAME_SNAKE}",
"justMyCode": true
}
]
}
}
+1 -1
View File
@@ -9,4 +9,4 @@ COPY . /home
WORKDIR /home
RUN uv sync --frozen --no-dev
CMD ["uv", "run", "./${REPO_NAME_SNAKE}/main.py"]
CMD ["uv", "run", "--frozen", "--no-dev", "-m", "${REPO_NAME_SNAKE}"]