Merge pull request #31 from ThomasRubini/lint
This commit is contained in:
commit
f15291031a
@ -1,9 +1,11 @@
|
|||||||
import flask
|
|
||||||
from flask_socketio import SocketIO
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
import flask
|
||||||
|
from flask_socketio import SocketIO
|
||||||
|
|
||||||
from truthseeker import discord_bot
|
from truthseeker import discord_bot
|
||||||
|
|
||||||
|
|
||||||
class TruthSeekerApp(flask.Flask):
|
class TruthSeekerApp(flask.Flask):
|
||||||
"""
|
"""
|
||||||
Main class of the app
|
Main class of the app
|
||||||
@ -26,14 +28,10 @@ class TruthSeekerApp(flask.Flask):
|
|||||||
self.discord_bot = discord_bot.DiscordBot()
|
self.discord_bot = discord_bot.DiscordBot()
|
||||||
token = os.getenv("DISCORD_BOT_TOKEN")
|
token = os.getenv("DISCORD_BOT_TOKEN")
|
||||||
if token:
|
if token:
|
||||||
pass
|
|
||||||
self.discord_bot.start(token)
|
self.discord_bot.start(token)
|
||||||
else:
|
else:
|
||||||
print("No token set. Not starting discord bot")
|
print("No token set. Not starting discord bot")
|
||||||
|
|
||||||
def run_app(self):
|
|
||||||
self.socketio_app.run(self)
|
|
||||||
|
|
||||||
APP = TruthSeekerApp()
|
APP = TruthSeekerApp()
|
||||||
|
|
||||||
from truthseeker.routes import routes_api, routes_ui, routes_socketio
|
from truthseeker.routes import routes_api, routes_ui, routes_socketio
|
||||||
|
@ -1,14 +1,17 @@
|
|||||||
import discord
|
|
||||||
import threading
|
import threading
|
||||||
import truthseeker
|
|
||||||
import asyncio
|
import asyncio
|
||||||
|
|
||||||
|
import discord
|
||||||
|
import truthseeker
|
||||||
|
|
||||||
|
|
||||||
class DiscordBot:
|
class DiscordBot:
|
||||||
"""
|
"""
|
||||||
Wrapper around a discord bot, providing utility methods to interact with it
|
Wrapper around a discord bot, providing utility methods to interact with it
|
||||||
|
|
||||||
:attr Client bot: the underlying discord bot from discord.py
|
:attr Client bot: the underlying discord bot from discord.py
|
||||||
:attr TextChannel __channel__: the channel used by the bot to send messages
|
:attr TextChannel __channel__: the channel used by the bot to send messages
|
||||||
|
:attr event_loop: event_loop used by discord.py. Used to schedule tasks from another thread
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
@ -17,38 +17,38 @@ url_object = eg.URL.create(
|
|||||||
engine = create_engine(url_object)
|
engine = create_engine(url_object)
|
||||||
session = Session(engine)
|
session = Session(engine)
|
||||||
|
|
||||||
def getTextFromLid(lang,lid) -> str:
|
def get_text_from_lid(lang,lid) -> str:
|
||||||
return session.query(tables.Locale).filter_by(LANG=lang, TEXT_ID=lid).one().TEXT
|
return session.query(tables.Locale).filter_by(LANG=lang, TEXT_ID=lid).one().TEXT
|
||||||
|
|
||||||
def getRandomPlace() -> tables.Place:
|
def get_random_place() -> tables.Place:
|
||||||
return random.choice(session.query(tables.Place).all())
|
return random.choice(session.query(tables.Place).all())
|
||||||
|
|
||||||
def getRandomNpc() -> tables.Npc :
|
def get_random_npc() -> tables.Npc :
|
||||||
return random.choice(session.query(tables.Npc).all())
|
return random.choice(session.query(tables.Npc).all())
|
||||||
|
|
||||||
def getNpcRandomTraitId(npc) -> int:
|
def get_npc_random_trait_id(npc) -> int:
|
||||||
reactions = session.query(tables.Reaction).filter_by(NPC_ID=npc.NPC_ID).all()
|
reactions = session.query(tables.Reaction).filter_by(NPC_ID=npc.NPC_ID).all()
|
||||||
reaction = random.choice(reactions)
|
reaction = random.choice(reactions)
|
||||||
return reaction.TRAIT_ID
|
return reaction.TRAIT_ID
|
||||||
|
|
||||||
def getNpcRandomAnswer(npc, QA_TYPE) -> tables.Answer :
|
def get_npc_random_answer(npc, QA_TYPE) -> tables.Answer :
|
||||||
answers = session.query(tables.Answer).filter_by(QA_TYPE=QA_TYPE,NPC_ID=npc.NPC_ID).all()
|
answers = session.query(tables.Answer).filter_by(QA_TYPE=QA_TYPE,NPC_ID=npc.NPC_ID).all()
|
||||||
return random.choice(answers)
|
return random.choice(answers)
|
||||||
|
|
||||||
def getRandomQuestion(QA_TYPE) -> tables.Answer :
|
def get_random_question(QA_TYPE) -> tables.Answer :
|
||||||
answers = session.query(tables.Question).filter_by(QUESTION_TYPE=QA_TYPE).all()
|
answers = session.query(tables.Question).filter_by(QUESTION_TYPE=QA_TYPE).all()
|
||||||
return random.choice(answers)
|
return random.choice(answers)
|
||||||
|
|
||||||
def getTraitFromText(text):
|
def get_trait_from_text(text):
|
||||||
trait_lid = session.query(tables.Locale).filter_by(TEXT=text).one().TEXT_ID
|
trait_lid = session.query(tables.Locale).filter_by(TEXT=text).one().TEXT_ID
|
||||||
return session.query(tables.Trait).filter_by(NAME_LID=trait_lid).one().TRAIT_ID
|
return session.query(tables.Trait).filter_by(NAME_LID=trait_lid).one().TRAIT_ID
|
||||||
|
|
||||||
def getTraitFromTraitId(trait_id):
|
def get_trait_from_trait_id(trait_id):
|
||||||
trait = session.query(tables.Trait).filter_by(TRAIT_ID=trait_id).one()
|
trait = session.query(tables.Trait).filter_by(TRAIT_ID=trait_id).one()
|
||||||
return trait
|
return trait
|
||||||
|
|
||||||
def getTraits(lang):
|
def get_traits(lang):
|
||||||
traits = []
|
traits = []
|
||||||
for trait in session.query(tables.Trait).all():
|
for trait in session.query(tables.Trait).all():
|
||||||
traits.append(getTextFromLid(lang,trait.NAME_LID))
|
traits.append(get_text_from_lid(lang,trait.NAME_LID))
|
||||||
return traits
|
return traits
|
@ -1,8 +1,8 @@
|
|||||||
from sqlalchemy import Column, Integer, Text, ForeignKey, VARCHAR
|
from sqlalchemy import Column, Integer, Text, ForeignKey, VARCHAR
|
||||||
from sqlalchemy.orm import declarative_base, relationship
|
from sqlalchemy.orm import declarative_base, relationship
|
||||||
|
|
||||||
Base = declarative_base()
|
|
||||||
|
|
||||||
|
Base = declarative_base()
|
||||||
|
|
||||||
class Locale(Base):
|
class Locale(Base):
|
||||||
__tablename__ = 'T_LOCALE'
|
__tablename__ = 'T_LOCALE'
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
import string
|
import string
|
||||||
import random
|
import random
|
||||||
|
from typing import Union
|
||||||
|
|
||||||
from truthseeker.logic.data_persistance.data_access import *
|
from truthseeker.logic.data_persistance.data_access import *
|
||||||
from datetime import datetime, timedelta
|
|
||||||
from truthseeker import APP
|
from truthseeker import APP
|
||||||
from typing import Union, Optional
|
|
||||||
|
|
||||||
def random_string(length: int) ->str:
|
def random_string(length: int) ->str:
|
||||||
"""
|
"""
|
||||||
@ -76,8 +76,8 @@ class Game:
|
|||||||
npcs[npc_id] = {}
|
npcs[npc_id] = {}
|
||||||
npcs[npc_id]["name"] = self.gamedata["npcs"][npc_id]["name"]
|
npcs[npc_id]["name"] = self.gamedata["npcs"][npc_id]["name"]
|
||||||
traitId = self.reaction_table[npc_id]
|
traitId = self.reaction_table[npc_id]
|
||||||
trait = getTraitFromTraitId(traitId)
|
trait = get_trait_from_trait_id(traitId)
|
||||||
npcs[npc_id]["reaction"] = getTextFromLid("FR",trait.NAME_LID)
|
npcs[npc_id]["reaction"] = get_text_from_lid("FR",trait.NAME_LID)
|
||||||
player_results = data["player"] = {}
|
player_results = data["player"] = {}
|
||||||
for member in self.members:
|
for member in self.members:
|
||||||
player_results[member.username] = member.results
|
player_results[member.username] = member.results
|
||||||
@ -130,7 +130,7 @@ class Game:
|
|||||||
results = {}
|
results = {}
|
||||||
try:
|
try:
|
||||||
for npc_id in responses:
|
for npc_id in responses:
|
||||||
trait_id = getTraitIdFromString(responses[npc_id])
|
trait_id = get_trait_id_from_string(responses[npc_id])
|
||||||
results[npc_id] = trait_id == str(self.reaction_table[npc_id])
|
results[npc_id] = trait_id == str(self.reaction_table[npc_id])
|
||||||
return results
|
return results
|
||||||
except:
|
except:
|
||||||
@ -200,20 +200,20 @@ def check_username(username: str) -> bool:
|
|||||||
|
|
||||||
def generateNpcText(npc: tables.Npc, lang: str) -> dict:
|
def generateNpcText(npc: tables.Npc, lang: str) -> dict:
|
||||||
data = {}
|
data = {}
|
||||||
data["name"] = getTextFromLid(lang, npc.NAME_LID)
|
data["name"] = get_text_from_lid(lang, npc.NAME_LID)
|
||||||
data["QA_0"] = getTextFromLid(lang, getNpcRandomAnswer(npc,0).TEXT_LID)
|
data["QA_0"] = get_text_from_lid(lang, get_npc_random_answer(npc,0).TEXT_LID)
|
||||||
data["QA_1"] = getTextFromLid(lang, getNpcRandomAnswer(npc,1).TEXT_LID)
|
data["QA_1"] = get_text_from_lid(lang, get_npc_random_answer(npc,1).TEXT_LID)
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def generateNpcReactions(npc: tables.Npc) ->list:
|
def generateNpcReactions(npc: tables.Npc) ->list:
|
||||||
return getNpcRandomTraitId(npc)
|
return get_npc_random_trait_id(npc)
|
||||||
|
|
||||||
def generatePlaceData(npcs: list, places: list, lang: str) -> dict:
|
def generate_place_data(npcs: list, places: list, lang: str) -> dict:
|
||||||
data = {}
|
data = {}
|
||||||
random.shuffle(npcs)
|
random.shuffle(npcs)
|
||||||
for place in places:
|
for place in places:
|
||||||
placedata = data[str(place.PLACE_ID)] = {}
|
placedata = data[str(place.PLACE_ID)] = {}
|
||||||
placedata["name"] = getTextFromLid(lang,place.NAME_LID)
|
placedata["name"] = get_text_from_lid(lang,place.NAME_LID)
|
||||||
placedata["npcs"] = []
|
placedata["npcs"] = []
|
||||||
for _ in npcs:
|
for _ in npcs:
|
||||||
placedata["npcs"].append(npcs.pop().NPC_ID)
|
placedata["npcs"].append(npcs.pop().NPC_ID)
|
||||||
@ -227,7 +227,7 @@ def generateGameData(LANG):
|
|||||||
reactions_table = {}
|
reactions_table = {}
|
||||||
npcs = []
|
npcs = []
|
||||||
while len(npcs) != 5:
|
while len(npcs) != 5:
|
||||||
npc = getRandomNpc()
|
npc = get_random_npc()
|
||||||
if npc not in npcs :
|
if npc not in npcs :
|
||||||
npcs.append(npc)
|
npcs.append(npc)
|
||||||
for npc in npcs:
|
for npc in npcs:
|
||||||
@ -236,15 +236,15 @@ def generateGameData(LANG):
|
|||||||
|
|
||||||
places = []
|
places = []
|
||||||
while len(places) != 3:
|
while len(places) != 3:
|
||||||
place = getRandomPlace()
|
place = get_random_place()
|
||||||
if place not in places:
|
if place not in places:
|
||||||
places.append(place)
|
places.append(place)
|
||||||
|
|
||||||
data["rooms"] = generatePlaceData(npcs,places,LANG)
|
data["rooms"] = generate_place_data(npcs,places,LANG)
|
||||||
data["questions"] = {}
|
data["questions"] = {}
|
||||||
data["questions"]["QA_0"] = getTextFromLid("FR",getRandomQuestion(0).TEXT_LID)
|
data["questions"]["QA_0"] = get_text_from_lid("FR",get_random_question(0).TEXT_LID)
|
||||||
data["questions"]["QA_1"] = getTextFromLid("FR",getRandomQuestion(1).TEXT_LID)
|
data["questions"]["QA_1"] = get_text_from_lid("FR",get_random_question(1).TEXT_LID)
|
||||||
data["traits"] = getTraits(LANG)
|
data["traits"] = get_traits(LANG)
|
||||||
return data, reactions_table
|
return data, reactions_table
|
||||||
|
|
||||||
def read_image(path:str):
|
def read_image(path:str):
|
||||||
@ -253,8 +253,8 @@ def read_image(path:str):
|
|||||||
except:
|
except:
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
def getTraitIdFromString(trait):
|
def get_trait_id_from_string(trait):
|
||||||
return getTraitFromText(trait)
|
return get_trait_from_text(trait)
|
||||||
|
|
||||||
def get_npc_image(npc_id):
|
def get_npc_image(npc_id):
|
||||||
return read_image(f"./truthseeker/static/images/npc/{npc_id}/0.png")
|
return read_image(f"./truthseeker/static/images/npc/{npc_id}/0.png")
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
import flask
|
|
||||||
import json
|
import json
|
||||||
|
|
||||||
|
import flask
|
||||||
|
|
||||||
from truthseeker import APP
|
from truthseeker import APP
|
||||||
from truthseeker.logic import game_logic
|
from truthseeker.logic import game_logic
|
||||||
|
|
||||||
|
@ -1,9 +1,11 @@
|
|||||||
from flask_socketio import join_room
|
|
||||||
import socketio
|
import socketio
|
||||||
|
|
||||||
|
from flask_socketio import join_room
|
||||||
|
|
||||||
from truthseeker import APP
|
from truthseeker import APP
|
||||||
from truthseeker.logic import game_logic
|
from truthseeker.logic import game_logic
|
||||||
|
|
||||||
|
|
||||||
@APP.socketio_app.on('connect')
|
@APP.socketio_app.on('connect')
|
||||||
def connect(auth):
|
def connect(auth):
|
||||||
if not (auth and "game_id" in auth):
|
if not (auth and "game_id" in auth):
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
import flask
|
import flask
|
||||||
|
|
||||||
from truthseeker.logic import game_logic
|
|
||||||
|
|
||||||
|
|
||||||
routes_ui = flask.Blueprint("ui", __name__)
|
routes_ui = flask.Blueprint("ui", __name__)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user