commit
						eb0d9082f1
					
				@ -2,6 +2,8 @@
 | 
			
		||||
FLASK_SECRET=""
 | 
			
		||||
DISCORD_BOT_TOKEN=""
 | 
			
		||||
ORIGIN="https://example.com"
 | 
			
		||||
GAME_TIMEOUT=1800
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
# Database
 | 
			
		||||
DB_HOST=""
 | 
			
		||||
 | 
			
		||||
@ -4,3 +4,4 @@ flask_sqlalchemy==3.0.2
 | 
			
		||||
pymysql==1.0.2
 | 
			
		||||
discord.py==2.1.0
 | 
			
		||||
python-dotenv==0.21.0
 | 
			
		||||
Flask-APScheduler==1.12.4
 | 
			
		||||
 | 
			
		||||
@ -19,6 +19,11 @@ def register_extensions(app):
 | 
			
		||||
 | 
			
		||||
    discord_bot.try_start()
 | 
			
		||||
 | 
			
		||||
    routes_api.scheduler.init_app(app)
 | 
			
		||||
    routes_api.scheduler.start()
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def register_routes(app):
 | 
			
		||||
    app.register_blueprint(routes_api.routes_api, url_prefix="/api/v1")
 | 
			
		||||
    app.register_blueprint(routes_ui.routes_ui, url_prefix="/")
 | 
			
		||||
 | 
			
		||||
@ -1,4 +1,5 @@
 | 
			
		||||
import string
 | 
			
		||||
import time
 | 
			
		||||
import random
 | 
			
		||||
from typing import Union
 | 
			
		||||
 | 
			
		||||
@ -61,6 +62,7 @@ class Game:
 | 
			
		||||
        self.has_started = False
 | 
			
		||||
        self.gamedata = {}
 | 
			
		||||
        self.reaction_table = {}
 | 
			
		||||
        self.creatation_timestamp = int(time.time())
 | 
			
		||||
 | 
			
		||||
    def set_owner(self, username: str) -> Member:
 | 
			
		||||
        """
 | 
			
		||||
 | 
			
		||||
@ -1,6 +1,7 @@
 | 
			
		||||
import json
 | 
			
		||||
import io
 | 
			
		||||
 | 
			
		||||
import time
 | 
			
		||||
import os
 | 
			
		||||
import flask
 | 
			
		||||
from sqlalchemy import select
 | 
			
		||||
 | 
			
		||||
@ -10,8 +11,20 @@ from truthinquiry.ext.discord_bot import discord_bot
 | 
			
		||||
from truthinquiry.ext.socketio import socket_io
 | 
			
		||||
from truthinquiry.logic import game_logic
 | 
			
		||||
 | 
			
		||||
from flask_apscheduler import APScheduler
 | 
			
		||||
scheduler = APScheduler()
 | 
			
		||||
scheduler.api_enabled = True
 | 
			
		||||
 | 
			
		||||
routes_api = flask.Blueprint("api", __name__)
 | 
			
		||||
@scheduler.task('interval', id='cleanup_games', seconds=1)
 | 
			
		||||
def cleanup():
 | 
			
		||||
    games_to_delete = []
 | 
			
		||||
    for game_id, game in game_logic.games_list.items():
 | 
			
		||||
        if game.creatation_timestamp + int(os.getenv("GAME_TIMEOUT")) < int(time.time()):
 | 
			
		||||
            games_to_delete.append(game_id)
 | 
			
		||||
    for game_id in games_to_delete:
 | 
			
		||||
        del game_logic.games_list[game_id]
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
# API specification is documented in api_doc.yml
 | 
			
		||||
 | 
			
		||||
@ -218,6 +231,6 @@ def check_anwser():
 | 
			
		||||
    if game.has_finished():
 | 
			
		||||
        json_game_results = game.generate_game_results()
 | 
			
		||||
        socket_io.emit("gamefinished", json_game_results, room="game."+game.game_id)
 | 
			
		||||
        del game
 | 
			
		||||
        del game_logic.games_list[game.game_id]
 | 
			
		||||
    response = {"error": 0}
 | 
			
		||||
    return response
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user