Fixed discordrest issue of not initializing properly

This commit is contained in:
Jeremy Zhang 2017-04-24 11:55:09 -07:00
parent a212ca1052
commit 9a698b7279
2 changed files with 10 additions and 5 deletions

View File

@ -2,7 +2,7 @@ from config import config
from database import db from database import db
from flask import Flask, render_template, request, session, url_for, redirect, jsonify from flask import Flask, render_template, request, session, url_for, redirect, jsonify
from flask_sslify import SSLify 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.api
import blueprints.user import blueprints.user
import blueprints.embed import blueprints.embed
@ -29,3 +29,7 @@ app.register_blueprint(blueprints.embed.embed, url_prefix="/embed", template_fol
@app.route("/") @app.route("/")
def index(): def index():
return render_template("index.html.j2") return render_template("index.html.j2")
@app.before_request
def before_request():
discord_api.init_discordrest()

View File

@ -4,7 +4,8 @@ import time
import json import json
from functools import partial from functools import partial
from titanembeds.utils import cache 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" _DISCORD_API_BASE = "https://discordapp.com/api/v6"
@ -20,6 +21,7 @@ class DiscordREST:
self.bot_token = bot_token self.bot_token = bot_token
self.user_agent = "TitanEmbeds (https://github.com/EndenDragon/Titan) Python/{} requests/{}".format(sys.version_info, requests.__version__) 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"): if not self._bucket_contains("global_limited"):
self._set_bucket("global_limited", False) self._set_bucket("global_limited", False)
self._set_bucket("global_limit_expire", 0) self._set_bucket("global_limit_expire", 0)
@ -29,11 +31,10 @@ class DiscordREST:
return value return value
def _set_bucket(self, key, 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): 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): def request(self, verb, url, **kwargs):
headers = { headers = {