Move the webhook listener into a cog so that I have access to the bot for the action method.
This commit is contained in:
@@ -1,9 +0,0 @@
|
|||||||
from fastapi import APIRouter
|
|
||||||
|
|
||||||
router = APIRouter()
|
|
||||||
|
|
||||||
|
|
||||||
@router.post("/message/")
|
|
||||||
async def hello():
|
|
||||||
print("we did a webhook")
|
|
||||||
return {"message": "webhook get"}
|
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
import uvicorn
|
||||||
|
from fastapi import FastAPI
|
||||||
|
from nextcord.ext import commands
|
||||||
|
|
||||||
|
app = FastAPI()
|
||||||
|
|
||||||
|
|
||||||
|
class ClanMessages(commands.Cog, name="Clan Messages"):
|
||||||
|
def __init__(self, bot: commands.Bot):
|
||||||
|
self.bot = bot
|
||||||
|
|
||||||
|
@commands.Cog.listener()
|
||||||
|
async def on_ready(self):
|
||||||
|
app.add_api_route("/message/", self.hello, methods=["POST"])
|
||||||
|
config = uvicorn.Config(app=app, port=5000, log_level="info")
|
||||||
|
server = uvicorn.Server(config)
|
||||||
|
await server.serve()
|
||||||
|
|
||||||
|
async def hello(self):
|
||||||
|
print("we did a webhook")
|
||||||
|
return {"message": "webhook get"}
|
||||||
|
|
||||||
|
async def update_messages(self):
|
||||||
|
# TODO everything
|
||||||
|
|
||||||
|
# git pull
|
||||||
|
# if no change, return
|
||||||
|
# for ever directory, sort the files by number then post
|
||||||
|
# posting involves checking if there is a message for that particular file then editing it or creating a
|
||||||
|
# new one. the message could be deleted, which would cause a new message to be sent and database updated.
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
# This function will be called when this extension is loaded.
|
||||||
|
# It is necessary to add these functions to the bot.
|
||||||
|
def setup(bot: commands.Bot):
|
||||||
|
"""Adds function to bot"""
|
||||||
|
bot.add_cog(ClanMessages(bot))
|
||||||
@@ -4,12 +4,9 @@ import sys
|
|||||||
|
|
||||||
import hydra
|
import hydra
|
||||||
import nextcord
|
import nextcord
|
||||||
import uvicorn
|
|
||||||
from fastapi import FastAPI
|
|
||||||
from hydra.core.config_store import ConfigStore
|
from hydra.core.config_store import ConfigStore
|
||||||
from nextcord.ext import commands
|
from nextcord.ext import commands
|
||||||
|
|
||||||
import classes.clan_message as clan_message
|
|
||||||
import database_setup.create_database as create_database
|
import database_setup.create_database as create_database
|
||||||
from classes.nominate_highcouncil_views import NominateHighCouncilView
|
from classes.nominate_highcouncil_views import NominateHighCouncilView
|
||||||
from classes.nominate_views import NominateView
|
from classes.nominate_views import NominateView
|
||||||
@@ -30,9 +27,6 @@ handler.setFormatter(
|
|||||||
)
|
)
|
||||||
logger.addHandler(handler)
|
logger.addHandler(handler)
|
||||||
|
|
||||||
app = FastAPI()
|
|
||||||
app.include_router(clan_message.router)
|
|
||||||
|
|
||||||
|
|
||||||
@hydra.main(config_path="conf", config_name="config")
|
@hydra.main(config_path="conf", config_name="config")
|
||||||
def main(cfg: DakinyConfig):
|
def main(cfg: DakinyConfig):
|
||||||
@@ -67,10 +61,6 @@ def main(cfg: DakinyConfig):
|
|||||||
bot.add_view(VoteHighcouncilView(cfg, bot.get_guild(cfg.params.guild_id)))
|
bot.add_view(VoteHighcouncilView(cfg, bot.get_guild(cfg.params.guild_id)))
|
||||||
print(f"{bot.user.name} has connected to Discord!")
|
print(f"{bot.user.name} has connected to Discord!")
|
||||||
|
|
||||||
config = uvicorn.Config("main:app", port=5000, log_level="info")
|
|
||||||
server = uvicorn.Server(config)
|
|
||||||
await server.serve()
|
|
||||||
|
|
||||||
# Run Discord bot
|
# Run Discord bot
|
||||||
bot.run(bot.config.params.discord_token)
|
bot.run(bot.config.params.discord_token)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user