dice challenges mark rolls as pass or fail
This commit is contained in:
parent
52370eabfc
commit
7f24914046
11
anonkun.py
11
anonkun.py
|
@ -10,8 +10,9 @@ from flask_paranoid import Paranoid
|
|||
from flask_session import Session
|
||||
from flask_socketio import SocketIO
|
||||
|
||||
from events import socketio
|
||||
import database as db
|
||||
from views import views
|
||||
from events import socketio
|
||||
|
||||
class ReverseProxied(object):
|
||||
"""
|
||||
|
@ -84,6 +85,14 @@ def unix2string(unix):
|
|||
return time.strftime(form, t)
|
||||
|
||||
|
||||
@app.template_filter("dice_chal")
|
||||
def get_dice_challenge(post_id):
|
||||
"""
|
||||
Returns the dice challenge for the given post_id.
|
||||
"""
|
||||
return db.get_dice_call(post_id)[3]
|
||||
|
||||
|
||||
init()
|
||||
if __name__ == "__main__":
|
||||
app.run(host='0.0.0.0', port=5050)
|
||||
|
|
|
@ -39,6 +39,7 @@ CREATE TABLE `quest_rolls` (
|
|||
`post_id` MEDIUMINT UNSIGNED NOT NULL,
|
||||
`roll_dice` TEXT NOT NULL,
|
||||
`roll_results` TEXT NOT NULL,
|
||||
`roll_total` SMALLINT UNSIGNED NOT NULL
|
||||
PRIMARY KEY (`message_id`)
|
||||
) ENGINE=InnoDB CHARSET utf8mb4;
|
||||
|
||||
|
|
10
database.py
10
database.py
|
@ -245,13 +245,15 @@ def get_dice_call(post_id):
|
|||
return data
|
||||
|
||||
|
||||
def insert_quest_roll(message_id, quest_id, post_id, roll_dice, roll_results):
|
||||
def insert_quest_roll(message_id, quest_id, post_id, roll_data):
|
||||
"""Inserts a user roll into the `quest_rolls` table."""
|
||||
ins = (message_id, quest_id, post_id) + roll_data
|
||||
_DB.execute(
|
||||
"INSERT INTO `quest_rolls`" \
|
||||
+ "(`message_id`, `quest_id`, `post_id`, `roll_dice`, `roll_results`)"\
|
||||
+ "VALUES (%s, %s, %s, %s, %s)",
|
||||
(message_id, quest_id, post_id, roll_dice, roll_results))
|
||||
+ "(`message_id`, `quest_id`, `post_id`, " \
|
||||
+ "`roll_dice`, `roll_results`, `roll_total`)" \
|
||||
+ "VALUES (%s, %s, %s, %s, %s, %s)",
|
||||
(ins))
|
||||
|
||||
|
||||
def get_quest_rolls(quest_id=None, post_id=None):
|
||||
|
|
13
events.py
13
events.py
|
@ -71,16 +71,23 @@ def message(data):
|
|||
dice_roll = re.search(r"(\d+d\d+(?:[+-]\d+)?)", message).group(1)
|
||||
if dice_call[2] and dice_roll != dice_call[1]:
|
||||
return
|
||||
roll_results = re.search(r"Rolled (.+)$", roll_msg).group(1)
|
||||
db.insert_quest_roll(
|
||||
message_id, room, dice_call_id, dice_roll, roll_results)
|
||||
roll_results = re.search(r"Rolled (.+) =", roll_msg).group(1)
|
||||
roll_total = int(re.search(r"= (\d+)$", roll_msg).group(1))
|
||||
roll_data = (dice_roll, roll_results, roll_total)
|
||||
db.insert_quest_roll(message_id, room, dice_call_id, roll_data)
|
||||
|
||||
if len(db.get_quest_rolls(post_id=dice_call_id)) == dice_call[4]:
|
||||
db.set_dice_call_closed(room)
|
||||
emit("close_dice_call", {"post_id": dice_call_id}, room=room)
|
||||
|
||||
room = data["room"]
|
||||
data = {}
|
||||
data["post"] = roll_msg + " (" + dice_roll + ")"
|
||||
if dice_call[3]:
|
||||
if roll_total >= dice_call[3]:
|
||||
data["post"] += " - Pass"
|
||||
else:
|
||||
data["post"] += " - Fail"
|
||||
data["post_type"] = "dice"
|
||||
data["post_id"] = dice_call_id
|
||||
emit("update_post", data, room=room)
|
||||
|
|
|
@ -207,11 +207,11 @@
|
|||
{{ quest_post[3] }}
|
||||
{% endautoescape %}
|
||||
{% elif quest_post[2] == "dice" %}
|
||||
<h3>{{ quest_post[3] }} - {% if quest_post[0] == dice_call %}Open{% else %}Closed{% endif %}</h3>
|
||||
<h3>{{ quest_post[3] }} - {% if quest_post[0] == dice_call_id %}Open{% else %}Closed{% endif %}</h3>
|
||||
{% for quest_roll in quest_rolls %}
|
||||
{% if quest_roll[2] == quest_post[0] %}
|
||||
<div id="questRollId-{{ quest_roll[0] }}">
|
||||
<b>Rolled {{ quest_roll[4] }} ({{ quest_roll[3] }})</b>
|
||||
<b>Rolled {{ quest_roll[4] }} = {{ quest_roll[5] }} ({{ quest_roll[3] }}){% if quest_post[0]|dice_chal != 0 %} - {% if quest_roll[5] >= quest_post[0]|dice_chal %}Pass{% else %} Fail{% endif %}{% endif %}</b>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
|
|
4
views.py
4
views.py
|
@ -54,7 +54,7 @@ def quest(quest_title):
|
|||
quest_id = data[0]
|
||||
quest_title = data[1]
|
||||
owner_id = data[3]
|
||||
dice_call = data[4]
|
||||
dice_call_id = data[4]
|
||||
quest_posts = db.get_quest_data(quest_id)
|
||||
quest_rolls = db.get_quest_rolls(quest_id)
|
||||
messages = db.get_chat_messages(quest_id)
|
||||
|
@ -64,7 +64,7 @@ def quest(quest_title):
|
|||
quest_posts=quest_posts,
|
||||
quest_rolls=quest_rolls,
|
||||
owner_id=owner_id,
|
||||
dice_call=dice_call,
|
||||
dice_call_id=dice_call_id,
|
||||
room_id=quest_id,
|
||||
messages=messages)
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user