Fill out some docustrings

This commit is contained in:
2024-05-15 13:46:13 -04:00
parent b9362f7eca
commit ee6b301791
+13 -6
View File
@@ -1,3 +1,7 @@
"""
File contains logic for creating a webhook listener, pulling from git, and updating all messages.
"""
import os import os
import nextcord import nextcord
@@ -18,6 +22,11 @@ MESSAGES_DIR = f"{REPO_DIR}/messages"
class ClanMessages(commands.Cog, name="Clan Messages"): class ClanMessages(commands.Cog, name="Clan Messages"):
"""
Cog to be loaded into the bot. Used to be able to have a fastapi post listener and access to the bot at
the same time.
"""
def __init__(self, bot: commands.Bot): def __init__(self, bot: commands.Bot):
self.bot = bot self.bot = bot
self.config: DakinyConfig = self.bot.config self.config: DakinyConfig = self.bot.config
@@ -29,18 +38,14 @@ class ClanMessages(commands.Cog, name="Clan Messages"):
Triggers when the bot is in ready state. Adds the webhook listener to FastAPI and serves. Triggers when the bot is in ready state. Adds the webhook listener to FastAPI and serves.
""" """
await self.update_messages() await self.update_messages()
app.add_api_route("/message/", self.hello, methods=["POST"]) app.add_api_route("/messages/", self.update_messages, methods=["POST"])
config = uvicorn.Config(app=app, port=5000, log_level="info") config = uvicorn.Config(app=app, port=5000, log_level="info")
server = uvicorn.Server(config) server = uvicorn.Server(config)
await server.serve() await server.serve()
async def hello(self):
await self.update_messages()
return
async def update_messages(self): async def update_messages(self):
""" """
_summary_ Pulls from git and then updates all the discord messages as described by the files in the git repo.
""" """
self.origin.pull() self.origin.pull()
@@ -92,6 +97,8 @@ class ClanMessages(commands.Cog, name="Clan Messages"):
session.execute(stmt) session.execute(stmt)
session.commit() session.commit()
return {"message": "Successfully updated all discord messages."}
async def get_clan_message_channel( async def get_clan_message_channel(
self, session: Session, channel_name: str, guild: nextcord.Guild self, session: Session, channel_name: str, guild: nextcord.Guild
) -> nextcord.TextChannel: ) -> nextcord.TextChannel: