From 9a698b72799f4b6b42ff2813d87f2cfa10bfb188 Mon Sep 17 00:00:00 2001 From: Jeremy Zhang Date: Mon, 24 Apr 2017 11:55:09 -0700 Subject: [PATCH] Fixed discordrest issue of not initializing properly --- titanembeds/app.py | 6 +++++- titanembeds/discordrest.py | 9 +++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/titanembeds/app.py b/titanembeds/app.py index b4bfe9e..c26f719 100644 --- a/titanembeds/app.py +++ b/titanembeds/app.py @@ -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, cache +from titanembeds.utils import rate_limiter, cache, discord_api import blueprints.api import blueprints.user import blueprints.embed @@ -29,3 +29,7 @@ app.register_blueprint(blueprints.embed.embed, url_prefix="/embed", template_fol @app.route("/") def index(): return render_template("index.html.j2") + +@app.before_request +def before_request(): + discord_api.init_discordrest() diff --git a/titanembeds/discordrest.py b/titanembeds/discordrest.py index 1343b31..9e0b989 100644 --- a/titanembeds/discordrest.py +++ b/titanembeds/discordrest.py @@ -4,7 +4,8 @@ import time import json from functools import partial from titanembeds.utils import cache -from titanembeds.database import db, KeyValueProperties, get_keyvalproperty, set_keyvalproperty +from titanembeds.database import db, KeyValueProperties, get_keyvalproperty, set_keyvalproperty, ifexists_keyvalproperty +from flask import request _DISCORD_API_BASE = "https://discordapp.com/api/v6" @@ -20,6 +21,7 @@ class DiscordREST: self.bot_token = bot_token self.user_agent = "TitanEmbeds (https://github.com/EndenDragon/Titan) Python/{} requests/{}".format(sys.version_info, requests.__version__) + def init_discordrest(self): if not self._bucket_contains("global_limited"): self._set_bucket("global_limited", False) self._set_bucket("global_limit_expire", 0) @@ -29,11 +31,10 @@ class DiscordREST: return value def _set_bucket(self, key, value): - #set_keyvalproperty("", "") - return ""#set_keyvalproperty(self.global_redis_prefix + key, value) + return set_keyvalproperty(self.global_redis_prefix + key, value) def _bucket_contains(self, key): - return ""#ifexists_keyvalproperty(self.global_redis_prefix + key) + return ifexists_keyvalproperty(self.global_redis_prefix + key) def request(self, verb, url, **kwargs): headers = {