diff --git a/truthinquiry/ext/database/models.py b/truthinquiry/ext/database/models.py index 3535f5c..957a8be 100644 --- a/truthinquiry/ext/database/models.py +++ b/truthinquiry/ext/database/models.py @@ -1,3 +1,5 @@ +import uuid + from sqlalchemy import Column, Integer, VARCHAR, Text, LargeBinary, ForeignKey from sqlalchemy.orm import relationship, declarative_base @@ -198,14 +200,16 @@ class Reaction(Base): IMG = Column(LargeBinary(length=2**24), comment="Binary data of the image associated to this npc and trait") NPC = relationship("Npc") TRAIT = relationship("Trait") + REACTION_UUID = Column(VARCHAR(255), unique=True, comment="ID of this reaction") def __init__(self, REACTION_ID, NPC_ID, TRAIT_ID): self.REACTION_ID = REACTION_ID self.NPC_ID = NPC_ID self.TRAIT_ID = TRAIT_ID + self.REACTION_UUID = uuid.uuid4() def __str__(self) -> str: - return f"Reaction(REACTION_ID={self.REACTION_ID}, NPC_ID={self.NPC_ID}, TRAIT_ID={self.TRAIT_ID})" + return f"Reaction(REACTION_ID={self.REACTION_ID}, NPC_ID={self.NPC_ID}, TRAIT_ID={self.TRAIT_ID}, REACTION_UUID={self.REACTION_UUID})" def __repr__(self) -> str: return self.__str__() \ No newline at end of file diff --git a/truthinquiry/routes/routes_api.py b/truthinquiry/routes/routes_api.py index c3728a0..1a89169 100644 --- a/truthinquiry/routes/routes_api.py +++ b/truthinquiry/routes/routes_api.py @@ -1,7 +1,11 @@ import json -import json -import flask +import io +import flask +from sqlalchemy import select + +from truthinquiry.ext.database.models import * +from truthinquiry.ext.database.fsa import db from truthinquiry.ext.discord_bot import discord_bot from truthinquiry.ext.socketio import socket_io from truthinquiry.logic import game_logic @@ -154,6 +158,20 @@ def get_npc_reaction(): 'Content-Disposition', 'attachment', filename='reaction.png') return response +@routes_api.route("/getReaction", methods=["GET", "POST"]) +def get_reaction(): + input_uuid = flask.request.values.get("uuid") + results = db.session.execute(select(Reaction).where(Reaction.REACTION_UUID==input_uuid)) + + row = results.first() + if row == None: + return {"error": 1, "msg": "No such reaction"} + reaction_obj = row[0] + + return flask.send_file(io.BytesIO(reaction_obj.IMG), mimetype='image/png') + + + @routes_api.route("/gameProgress", methods=["GET", "POST"]) def game_progress():