mirror of
https://github.com/TitanEmbeds/Titan.git
synced 2025-06-16 11:25:22 +02:00
Show global header message when bot loses connection with server
This commit is contained in:
@ -2,7 +2,7 @@ from config import config
|
||||
from database import db
|
||||
from flask import Flask, render_template, request, session, url_for, redirect, jsonify
|
||||
from flask_sslify import SSLify
|
||||
from titanembeds.utils import rate_limiter, discord_api
|
||||
from titanembeds.utils import rate_limiter, discord_api, bot_alive
|
||||
import blueprints.api
|
||||
import blueprints.user
|
||||
import blueprints.embed
|
||||
@ -38,3 +38,8 @@ def about():
|
||||
def before_request():
|
||||
db.create_all()
|
||||
discord_api.init_discordrest()
|
||||
|
||||
@app.context_processor
|
||||
def context_processor():
|
||||
bot_status = bot_alive()
|
||||
return {"bot_status": bot_status}
|
@ -21,6 +21,7 @@
|
||||
{% endif %}
|
||||
</head>
|
||||
<body>
|
||||
{% include 'nobot_header.html.j2' %}
|
||||
<div class="navbar-fixed">
|
||||
<nav>
|
||||
<div class="nav-wrapper">
|
||||
@ -76,6 +77,7 @@
|
||||
|
||||
<div id="loginmodal" class="modal">
|
||||
<div class="modal-content">
|
||||
{% include 'nobot_header.html.j2' %}
|
||||
<h4>{{ login_greeting }}</h4>
|
||||
<div id="loginmodal-maincontent" class="row valign-wrap">
|
||||
<div id="modal_guildinfobox" class="col m3 s12 center-align">
|
||||
|
10
webapp/titanembeds/templates/nobot_header.html.j2
Normal file
10
webapp/titanembeds/templates/nobot_header.html.j2
Normal file
@ -0,0 +1,10 @@
|
||||
{% if not bot_status["status"] %}
|
||||
<div style="border: solid 3px red; background-color: yellow; color: black;">
|
||||
<p>
|
||||
<strong>NOTICE!</strong>
|
||||
The bot is <strong>currently not online</strong> or has <strong>lost the connection</strong> to the webserver.
|
||||
If you see this header, please <a href="https://discord.io/titan" target="_blank" style="background-color: orange; color: blue;">notify us</a> as soon as possible for us to fix this issue.
|
||||
Down since approximately <code>{{ bot_status["formatted_utc"] }}</code> UTC (<code>{{ bot_status["epoch_seconds"] }} epoch seconds</code>).
|
||||
</p>
|
||||
</div>
|
||||
{% endif %}
|
@ -19,6 +19,7 @@
|
||||
{% include 'google_analytics.html.j2' %}
|
||||
</head>
|
||||
<body>
|
||||
{% include 'nobot_header.html.j2' %}
|
||||
<main>
|
||||
{% if session['unauthenticated'] is defined and not session['unauthenticated'] %}
|
||||
<ul id="menu_dropdown" class="dropdown-content">
|
||||
|
@ -1,10 +1,11 @@
|
||||
from titanembeds.database import db, Guilds, KeyValueProperties
|
||||
from titanembeds.database import db, Guilds, KeyValueProperties, get_keyvalproperty
|
||||
from flask import request, session
|
||||
from flask_limiter import Limiter
|
||||
from config import config
|
||||
import random
|
||||
import string
|
||||
import hashlib
|
||||
import time
|
||||
|
||||
from titanembeds.discordrest import DiscordREST
|
||||
|
||||
@ -72,5 +73,19 @@ def guild_accepts_visitors(guild_id):
|
||||
def guild_query_unauth_users_bool(guild_id):
|
||||
dbGuild = db.session.query(Guilds).filter(Guilds.guild_id==guild_id).first()
|
||||
return dbGuild.unauth_users
|
||||
|
||||
def bot_alive():
|
||||
results = {"status": False, "formatted_utc": "Never", "epoch_seconds": None}
|
||||
epoch = get_keyvalproperty("bot_heartbeat")
|
||||
if not epoch:
|
||||
return results
|
||||
epoch = float(epoch)
|
||||
utc = time.strftime("%Y-%m-%d %H:%M:%S", time.gmtime(epoch))
|
||||
results["formatted_utc"] = utc
|
||||
results["epoch_seconds"] = epoch
|
||||
now = time.time()
|
||||
if now - epoch < 60 * 5:
|
||||
results["status"] = True
|
||||
return results
|
||||
|
||||
rate_limiter = Limiter(key_func=get_client_ipaddr) # Default limit by ip address
|
||||
|
Reference in New Issue
Block a user