Skip to content

Commit

Permalink
discord webhook for granting case
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh Smith committed Dec 17, 2023
1 parent a13a90f commit b1e5db4
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ DB_PASS=lol123
DB_USE_SSL=false
INITIALLY_AVAILABLE_DB=postgres

DISCORD_WEBHOOK_URL=

PAYPAL_BUSINESS_EMAIL=[email protected]
SHOULD_ENFORCE_UNIQUE_PAYMENTS=true
SHOULD_REQUIRE_IPN_VERIFICATION=true
20 changes: 20 additions & 0 deletions app/api/webhooks/paypal.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import urllib.parse
import uuid

from discord_webhook import AsyncDiscordWebhook
from discord_webhook.webhook import DiscordEmbed
from fastapi import APIRouter
from fastapi import Header
from fastapi import Request
Expand Down Expand Up @@ -287,6 +289,24 @@ async def process_notification(
},
)

webhook = AsyncDiscordWebhook(
url=settings.DISCORD_WEBHOOK_URL,
content="Granting donation perks to user",
embeds=[
DiscordEmbed(title="User ID", description=f"{user_id}"),
DiscordEmbed(title="Username", description=f"{username}"),
DiscordEmbed(title="Donation Tier", description=f"{donation_tier}"),
DiscordEmbed(title="Donation Months", description=f"{donation_months}"),
DiscordEmbed(title="Donation Amount", description=f"{donation_amount}"),
DiscordEmbed(title="Donation Currency", description=f"{donation_currency}"),
DiscordEmbed(title="New Privileges", description=f"{privileges}"),
DiscordEmbed(title="New Donor Expire", description=f"{donor_expire}"),
DiscordEmbed(title="New User Badges", description=f"{user_badge_ids}"),
DiscordEmbed(title="Transaction ID", description=f"{transaction_id}"),
],
)
await webhook.execute()

# make writes to the database
if settings.SHOULD_WRITE_TO_USERS_DB:
async with clients.database.transaction():
Expand Down
2 changes: 2 additions & 0 deletions app/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ def read_bool(value: str) -> bool:

PAYPAL_BUSINESS_EMAIL = os.environ["PAYPAL_BUSINESS_EMAIL"]

DISCORD_WEBHOOK_URL = os.environ["DISCORD_WEBHOOK_URL"]

# temp/feature flags
SHOULD_WRITE_TO_USERS_DB = read_bool(os.environ["SHOULD_WRITE_TO_USERS_DB"])
SHOULD_ENFORCE_UNIQUE_PAYMENTS = read_bool(os.environ["SHOULD_ENFORCE_UNIQUE_PAYMENTS"])
Expand Down

0 comments on commit b1e5db4

Please sign in to comment.