strict rolls are enforced and dice call will close after rolls_taken is met
This commit is contained in:
parent
06583bb346
commit
52370eabfc
16
database.py
16
database.py
|
@ -254,10 +254,16 @@ def insert_quest_roll(message_id, quest_id, post_id, roll_dice, roll_results):
|
||||||
(message_id, quest_id, post_id, roll_dice, roll_results))
|
(message_id, quest_id, post_id, roll_dice, roll_results))
|
||||||
|
|
||||||
|
|
||||||
def get_quest_rolls(quest_id):
|
def get_quest_rolls(quest_id=None, post_id=None):
|
||||||
"""Gets all rolls for the given quest."""
|
"""Gets all rolls for the given quest."""
|
||||||
data = _DB.execute(
|
if quest_id:
|
||||||
"SELECT * FROM `quest_rolls` WHERE `quest_id` = %s " \
|
sql = "SELECT * FROM `quest_rolls` WHERE `quest_id` = %s "
|
||||||
+ "ORDER BY `message_id` ASC",
|
ins = quest_id
|
||||||
(quest_id,)).fetchall()
|
elif post_id:
|
||||||
|
sql = "SELECT * FROM `quest_rolls` WHERE `post_id` = %s "
|
||||||
|
ins = post_id
|
||||||
|
else:
|
||||||
|
return
|
||||||
|
sql += "ORDER BY `message_id` ASC"
|
||||||
|
data = _DB.execute(sql, (ins,)).fetchall()
|
||||||
return data
|
return data
|
||||||
|
|
|
@ -69,10 +69,15 @@ def message(data):
|
||||||
if dice_call_id:
|
if dice_call_id:
|
||||||
dice_call = db.get_dice_call(dice_call_id)
|
dice_call = db.get_dice_call(dice_call_id)
|
||||||
dice_roll = re.search(r"(\d+d\d+(?:[+-]\d+)?)", message).group(1)
|
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)
|
roll_results = re.search(r"Rolled (.+)$", roll_msg).group(1)
|
||||||
db.insert_quest_roll(
|
db.insert_quest_roll(
|
||||||
message_id, room, dice_call_id, dice_roll, roll_results)
|
message_id, room, dice_call_id, dice_roll, roll_results)
|
||||||
|
|
||||||
|
if len(db.get_quest_rolls(post_id=dice_call_id)) == dice_call[4]:
|
||||||
|
emit("close_dice_call", {"post_id": dice_call_id}, room=room)
|
||||||
|
|
||||||
room = data["room"]
|
room = data["room"]
|
||||||
data = {}
|
data = {}
|
||||||
data["post"] = roll_msg + " (" + dice_roll + ")"
|
data["post"] = roll_msg + " (" + dice_roll + ")"
|
||||||
|
|
|
@ -64,10 +64,14 @@
|
||||||
socket.on('close_dice_call', function(data) {
|
socket.on('close_dice_call', function(data) {
|
||||||
let post = document.getElementById('questPostData-' + data.post_id);
|
let post = document.getElementById('questPostData-' + data.post_id);
|
||||||
post.children[0].textContent = post.children[0].textContent.replace('Open', 'Closed');
|
post.children[0].textContent = post.children[0].textContent.replace('Open', 'Closed');
|
||||||
|
document.getElementById('close_dc-' + data.post_id).style.display = 'none';
|
||||||
|
document.getElementById('open_dc-' + data.post_id).style.display = 'initial';
|
||||||
});
|
});
|
||||||
socket.on('open_dice_call', function(data) {
|
socket.on('open_dice_call', function(data) {
|
||||||
let post = document.getElementById('questPostData-' + data.post_id);
|
let post = document.getElementById('questPostData-' + data.post_id);
|
||||||
post.firstElementChild.textContent = post.firstElementChild.textContent.replace('Closed', 'Open');
|
post.firstElementChild.textContent = post.firstElementChild.textContent.replace('Closed', 'Open');
|
||||||
|
document.getElementById('close_dc-' + data.post_id).style.display = 'initial';
|
||||||
|
document.getElementById('open_dc-' + data.post_id).style.display = 'none';
|
||||||
});
|
});
|
||||||
let mtarea = document.getElementById('messageTextArea');
|
let mtarea = document.getElementById('messageTextArea');
|
||||||
mtarea.addEventListener('keypress', function(event) {
|
mtarea.addEventListener('keypress', function(event) {
|
||||||
|
@ -127,13 +131,9 @@
|
||||||
document.getElementById('QMDicePostForm').reset();
|
document.getElementById('QMDicePostForm').reset();
|
||||||
}
|
}
|
||||||
function close_dice_call(post_id) {
|
function close_dice_call(post_id) {
|
||||||
document.getElementById('close_dc-' + post_id).style.display = 'none';
|
|
||||||
document.getElementById('open_dc-' + post_id).style.display = 'initial';
|
|
||||||
socket.emit('close_dice_call', {post_id: post_id, room: {{ room_id }}});
|
socket.emit('close_dice_call', {post_id: post_id, room: {{ room_id }}});
|
||||||
}
|
}
|
||||||
function open_dice_call(post_id) {
|
function open_dice_call(post_id) {
|
||||||
document.getElementById('close_dc-' + post_id).style.display = 'initial';
|
|
||||||
document.getElementById('open_dc-' + post_id).style.display = 'none';
|
|
||||||
socket.emit('open_dice_call', {post_id: post_id, room: {{ room_id }}});
|
socket.emit('open_dice_call', {post_id: post_id, room: {{ room_id }}});
|
||||||
}
|
}
|
||||||
function deactivate_post() {
|
function deactivate_post() {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user