Remove global header when the bot is not connected to the database

This commit is contained in:
Jeremy Zhang
2017-09-11 20:33:20 +00:00
parent 9ef8ef7c90
commit 8a7e3322b9
9 changed files with 3 additions and 110 deletions

View File

@ -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, bot_alive, socketio
from titanembeds.utils import rate_limiter, discord_api, socketio
from .blueprints import api, user, admin, embed, gateway
import os
from titanembeds.database import get_administrators_list
@ -53,5 +53,4 @@ def before_request():
@app.context_processor
def context_processor():
bot_status = bot_alive()
return {"bot_status": bot_status, "devs": get_administrators_list()}
return {"devs": get_administrators_list()}

View File

@ -24,7 +24,6 @@
{% endif %}
</head>
<body>
{% include 'nobot_header.html.j2' %}
<div class="navbar-fixed">
<nav>
<div class="nav-wrapper">
@ -78,7 +77,6 @@
<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">

View File

@ -1,10 +0,0 @@
{% 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 %}

View File

@ -23,7 +23,6 @@
{% 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">

View File

@ -1,4 +1,4 @@
from titanembeds.database import db, Guilds, KeyValueProperties, get_keyvalproperty
from titanembeds.database import db, Guilds
from flask import request, session
from flask_limiter import Limiter
from flask_socketio import SocketIO
@ -74,20 +74,6 @@ 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
socketio = SocketIO()