diff --git a/divent/bot.py b/divent/bot.py index 8d03106..eaa55df 100644 --- a/divent/bot.py +++ b/divent/bot.py @@ -97,6 +97,17 @@ def days_before_failure(): return nextDelta.days +@app.errorhandler(500) +async def errorhandler(error: Exception): + print(f"\33[31m{error}\33[m") + return await render_template("error.html.j2", error=str(error)), 500 + + +@app.errorhandler(404) +async def not_found(error: Exception): + return await render_template("error.html.j2", error=str(error)), 404 + + @app.context_processor def context_processor(): return dict(days_before_failure=days_before_failure(), _=i18n, bot=client.user) @@ -118,7 +129,9 @@ async def login(): if token is not None: return redirect(url_for(".guilds")) - discord = make_oauth_session(host_url=request.host_url, scope=["guilds"]) + discord = make_oauth_session( + host_url=request.host_url, scope=["identify", "guilds"] + ) authorization_url, state = discord.authorization_url(AUTHORIZATION_BASE_URL) session["oauth2_state"] = state return redirect(authorization_url) @@ -148,13 +161,19 @@ async def guilds(): return redirect(url_for(".login")) discord = make_oauth_session(host_url=request.host_url, token=token) - guilds = discord.get(API_BASE_URL + "/users/@me/guilds").json() + user = discord.get(API_BASE_URL + "/users/@me") + guilds = discord.get(API_BASE_URL + "/users/@me/guilds") - return await render_template("guilds.html.j2", guilds=guilds) + if user.status_code != 200 or guilds.status_code != 200: + return redirect(url_for(".login")) + + return await render_template( + "guilds.html.j2", guilds=guilds.json(), user=user.json() + ) @app.route("/.ics") -async def ical(guild_id): +async def ical(guild_id: str): guild = get_guild_by_id(guild_id) if guild is None: return redirect(url_for(".login")) diff --git a/divent/static/css/global.css b/divent/static/css/global.css index ada5494..f420b5d 100644 --- a/divent/static/css/global.css +++ b/divent/static/css/global.css @@ -22,7 +22,6 @@ body { #content { min-width: 280px; max-width: 400px; - min-height: 400px; background-color: #18191c; border-radius: 5px; box-shadow: 0 8px 16px rgba(0, 0, 0, 0.24); diff --git a/divent/static/img/deadlink.png b/divent/static/img/deadlink.png new file mode 100644 index 0000000..d87b3e3 Binary files /dev/null and b/divent/static/img/deadlink.png differ diff --git a/divent/templates/error.html.j2 b/divent/templates/error.html.j2 new file mode 100644 index 0000000..98873cc --- /dev/null +++ b/divent/templates/error.html.j2 @@ -0,0 +1,21 @@ +{% extends "base.html.j2" %} +{% block content %} +
+
+ {{ _('Link is dead') }} +
+
+ + {{ error }} + +
+
+ + + {{ _('Back to the beginning') }} + +
+{% endblock content %} diff --git a/divent/templates/footer.html.j2 b/divent/templates/footer.html.j2 new file mode 100644 index 0000000..c0e1a31 --- /dev/null +++ b/divent/templates/footer.html.j2 @@ -0,0 +1,30 @@ + diff --git a/divent/templates/guilds.html.j2 b/divent/templates/guilds.html.j2 index cac471a..981f3c1 100644 --- a/divent/templates/guilds.html.j2 +++ b/divent/templates/guilds.html.j2 @@ -1,5 +1,18 @@ {% extends "base.html.j2" %} {% block content %} +
+
+ {{ _('Bot Logo') }} + ... + {{ _('User Logo') }} +
+