Merge branch 'main' into gamelimit
This commit is contained in:
commit
5544eb439d
@ -3,6 +3,7 @@ FLASK_SECRET=""
|
||||
DISCORD_BOT_TOKEN=""
|
||||
ORIGIN="https://example.com"
|
||||
GAME_LIMIT=100
|
||||
GAME_TIMEOUT=1800
|
||||
|
||||
# Database
|
||||
DB_HOST=""
|
||||
|
1
.github/workflows/tests.yml
vendored
1
.github/workflows/tests.yml
vendored
@ -17,6 +17,7 @@ jobs:
|
||||
|
||||
- name: Run tests
|
||||
env:
|
||||
GAME_LIMIT: 100
|
||||
FLASK_SECRET: ${{SECRETS.FLASK_SECRET}}
|
||||
DB_HOST: ${{SECRETS.DB_HOST}}
|
||||
DB_PORT: ${{SECRETS.DB_PORT}}
|
||||
|
@ -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
|
||||
import os
|
||||
from sqlalchemy import select
|
||||
@ -12,8 +13,20 @@ from truthinquiry.ext.socketio import socket_io
|
||||
from truthinquiry.logic import game_logic
|
||||
from dotenv import load_dotenv
|
||||
|
||||
load_dotenv()
|
||||
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
|
||||
|
||||
@ -221,6 +234,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