yeet
This commit is contained in:
10
.gitignore
vendored
Normal file
10
.gitignore
vendored
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
# Python-generated files
|
||||||
|
__pycache__/
|
||||||
|
*.py[oc]
|
||||||
|
build/
|
||||||
|
dist/
|
||||||
|
wheels/
|
||||||
|
*.egg-info
|
||||||
|
|
||||||
|
# Virtual environments
|
||||||
|
.venv
|
||||||
1
.python-version
Normal file
1
.python-version
Normal file
@@ -0,0 +1 @@
|
|||||||
|
3.13
|
||||||
13
Dockerfile
Normal file
13
Dockerfile
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
FROM python:3.13-slim
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
COPY pyproject.toml .
|
||||||
|
COPY main.py .
|
||||||
|
COPY lookup.txt .
|
||||||
|
|
||||||
|
RUN pip install flask httpx
|
||||||
|
|
||||||
|
EXPOSE 5000
|
||||||
|
|
||||||
|
CMD ["python", "-m", "flask", "--app", "main", "run", "--host=0.0.0.0"]
|
||||||
12
docker-compose.yml
Normal file
12
docker-compose.yml
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
version: '3.8'
|
||||||
|
|
||||||
|
services:
|
||||||
|
webhookproxy:
|
||||||
|
build: .
|
||||||
|
ports:
|
||||||
|
- "5000:5000"
|
||||||
|
environment:
|
||||||
|
- FLASK_ENV=production
|
||||||
|
volumes:
|
||||||
|
- ./lookup.txt:/app/lookup.txt:ro
|
||||||
|
restart: unless-stopped
|
||||||
66
main.py
Normal file
66
main.py
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
from flask import Flask
|
||||||
|
|
||||||
|
app = Flask(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
def populate_webhook_lookup():
|
||||||
|
lookup = {}
|
||||||
|
with open("./lookup.txt") as file:
|
||||||
|
for line in file:
|
||||||
|
split_line = line.split(",")
|
||||||
|
lookup[split_line[0]]: split_line[1]
|
||||||
|
return lookup
|
||||||
|
|
||||||
|
UUID_TO_WEBHOOK_LOOKUP = populate_webhook_lookup()
|
||||||
|
|
||||||
|
def convert_ghost_to_discord(ghost_payload):
|
||||||
|
post = ghost_payload.get("post").get("current")
|
||||||
|
return {
|
||||||
|
"embeds": [{
|
||||||
|
"title": post.get("title"),
|
||||||
|
"description": post.get("excerpt")[:200] + "...",
|
||||||
|
"url": f"https://torrtle.co/{post.get('slug')",
|
||||||
|
"color": "0x00ff00",
|
||||||
|
"thumbnail": {
|
||||||
|
"url": post.get("feature_image")
|
||||||
|
},
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"name": "Author",
|
||||||
|
"value": post.get("primary_author").get("name"),
|
||||||
|
"inline": True
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Published",
|
||||||
|
"value": post.get("published_at"),
|
||||||
|
"inline": True,
|
||||||
|
}
|
||||||
|
],
|
||||||
|
|
||||||
|
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
|
||||||
|
@app.route("/")
|
||||||
|
def home():
|
||||||
|
return "This is a silly web util that converts the Ghost webhook payloads to Discord payloads"
|
||||||
|
|
||||||
|
|
||||||
|
@app.route("/:uuid", methods=["POST"])
|
||||||
|
def convert(uuid):
|
||||||
|
webhook = UUID_TO_WEBHOOK_LOOKUP.get(uuid)
|
||||||
|
ghost_payload = request.get_json()
|
||||||
|
discord_payload = convert_ghost_to_discord(ghost_payload)
|
||||||
|
|
||||||
|
httpx.post(webhook, data=discord_payload)
|
||||||
|
|
||||||
|
return 200
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
print("Hello from webhookproxy!")
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
7
pyproject.toml
Normal file
7
pyproject.toml
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
[project]
|
||||||
|
name = "webhookproxy"
|
||||||
|
version = "0.1.0"
|
||||||
|
description = "Add your description here"
|
||||||
|
readme = "README.md"
|
||||||
|
requires-python = ">=3.13"
|
||||||
|
dependencies = []
|
||||||
Reference in New Issue
Block a user