Skip to content

Commit

Permalink
Add an alert related to heroku
Browse files Browse the repository at this point in the history
Add an alert on webpage when HEROKU_APP_NAME is invalid
  • Loading branch information
BattlefieldDuck committed Nov 6, 2022
1 parent 0990679 commit 7ac12d8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
16 changes: 13 additions & 3 deletions app.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import json
import os
import re

from dotenv import load_dotenv
from flask import Flask, jsonify, render_template
from flask import Flask, jsonify, render_template, request

from discordgsm.database import Database
from discordgsm.main import tree
from discordgsm.service import gamedig, invite_link, public, whitelist_guilds
from discordgsm.translator import translations, Locale
from discordgsm.translator import Locale, translations
from discordgsm.version import __version__

load_dotenv()
Expand All @@ -18,7 +19,16 @@

@app.route('/')
def index():
return render_template('index.html', invite_link=invite_link)
show_alert = False
heroku_app_name = ''

if match := re.search(r':\/\/([a-z|\d|-]+)\.herokuapp\.com', request.base_url):
heroku_app_name = match.groups()[0]

if os.getenv('HEROKU_APP_NAME').strip() != heroku_app_name:
show_alert = True

return render_template('index.html', invite_link=invite_link, show_alert=show_alert, heroku_app_name=heroku_app_name)


if os.getenv('WEB_API_ENABLE', '').lower() == 'true':
Expand Down
8 changes: 8 additions & 0 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@
<body>
<div id="particles-js"></div>

{% if show_alert %}
<div class="alert alert-danger mx-4 mb-5" role="alert">
Incorrect environment variables for HEROKU_APP_NAME<br>
Please set the value to {{ heroku_app_name }}<br>
Otherwise your discord bot will sleeps after 30 minutes of inactivity
</div>
{% endif %}

<div class="message">
<img src="android-chrome-256x256.png" width="60" alt="DiscordGSM Logo">
<div class="message__title">DiscordGSM Deployed</div>
Expand Down

0 comments on commit 7ac12d8

Please sign in to comment.