-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
API integration for calidum-rotae requests (#46)
closes #45 Summary: This pull request introduces several changes to the existing Discord bot and its API integration to allow for handling webhooks request coming from calidum rotae. - API Bot Endpoint: The Quart API endpoint /webhooks/<uuid> - payload validation and parsing. - relay calidum-rotae http requests to discord - Bot Updates - New Webhook Commands: Added new Slash command group named webhook which includes the commands create, list, delete, and update. - Unique Webhook URL Generation: Implemented a utility function generate_unique_webhook_url() for generating unique URLs for each webhook. - Database Integration: Connected the bot with the database to store and fetch webhook data.
- Loading branch information
Showing
11 changed files
with
260 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,8 @@ services: | |
- .env | ||
networks: | ||
- app_network | ||
ports: | ||
- 6000:6000 | ||
|
||
networks: | ||
app_network: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,5 @@ jsonschema==4.7.2 | |
pymongo==4.1.1 | ||
pytest~=7.2.0 | ||
discord~=2.1.0 | ||
pytz~=2023.3 | ||
pytz~=2023.3 | ||
quart~=0.18.4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from .routes import create_routes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
from discord import\ | ||
Embed | ||
import re | ||
from quart import request, jsonify | ||
|
||
def create_routes(app, database, trema): | ||
create_routes_webhooks(app, database, trema) | ||
|
||
def create_routes_webhooks(app, database, trema): | ||
@app.route('/webhooks/<uuid>', methods=['POST']) | ||
async def handle_webhook(uuid): | ||
channelID = database.get_channel_by_webhook(uuid) | ||
if channelID is None: | ||
return jsonify({'error': 'Invalid webhook UUID'}), 400 | ||
|
||
incoming_data = await request.json | ||
embed_data = incoming_data.get('embeds', [])[0] | ||
|
||
embed = Embed( | ||
title=embed_data.get('title', 'N/A'), | ||
color=int(embed_data.get('color', '0')) | ||
) | ||
|
||
description = embed_data.get('description', 'N/A') | ||
|
||
fields = re.findall(r"\*\*(.+?):\*\* (.+?)(?=\n|$)", description) | ||
for name, value in fields: | ||
embed.add_field(name=name, value=value, inline=False if "Details" in name else True) | ||
|
||
footer_data = embed_data.get('footer', {}) | ||
footer_text = footer_data.get('text', '') | ||
if footer_text: | ||
embed.set_footer(text=footer_text) | ||
|
||
channel = trema.get_channel(int(channelID)) | ||
await channel.send(embed=embed) | ||
|
||
return jsonify({'status': 'success'}), 200 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"type": "object", | ||
"properties": { | ||
"webhookName": {"type": "string"}, | ||
"channelID": {"type": "string"}, | ||
"unique_url": {"type": "string"} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.