Compare commits
2 Commits
06583bb346
...
7f24914046
Author | SHA1 | Date | |
---|---|---|---|
7f24914046 | |||
52370eabfc |
11
anonkun.py
11
anonkun.py
|
@ -10,8 +10,9 @@ from flask_paranoid import Paranoid
|
||||||
from flask_session import Session
|
from flask_session import Session
|
||||||
from flask_socketio import SocketIO
|
from flask_socketio import SocketIO
|
||||||
|
|
||||||
from events import socketio
|
import database as db
|
||||||
from views import views
|
from views import views
|
||||||
|
from events import socketio
|
||||||
|
|
||||||
class ReverseProxied(object):
|
class ReverseProxied(object):
|
||||||
"""
|
"""
|
||||||
|
@ -84,6 +85,14 @@ def unix2string(unix):
|
||||||
return time.strftime(form, t)
|
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()
|
init()
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
app.run(host='0.0.0.0', port=5050)
|
app.run(host='0.0.0.0', port=5050)
|
||||||
|
|
|
@ -39,6 +39,7 @@ CREATE TABLE `quest_rolls` (
|
||||||
`post_id` MEDIUMINT UNSIGNED NOT NULL,
|
`post_id` MEDIUMINT UNSIGNED NOT NULL,
|
||||||
`roll_dice` TEXT NOT NULL,
|
`roll_dice` TEXT NOT NULL,
|
||||||
`roll_results` TEXT NOT NULL,
|
`roll_results` TEXT NOT NULL,
|
||||||
|
`roll_total` SMALLINT UNSIGNED NOT NULL
|
||||||
PRIMARY KEY (`message_id`)
|
PRIMARY KEY (`message_id`)
|
||||||
) ENGINE=InnoDB CHARSET utf8mb4;
|
) ENGINE=InnoDB CHARSET utf8mb4;
|
||||||
|
|
||||||
|
|
26
database.py
26
database.py
|
@ -245,19 +245,27 @@ def get_dice_call(post_id):
|
||||||
return data
|
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."""
|
"""Inserts a user roll into the `quest_rolls` table."""
|
||||||
|
ins = (message_id, quest_id, post_id) + roll_data
|
||||||
_DB.execute(
|
_DB.execute(
|
||||||
"INSERT INTO `quest_rolls`" \
|
"INSERT INTO `quest_rolls`" \
|
||||||
+ "(`message_id`, `quest_id`, `post_id`, `roll_dice`, `roll_results`)"\
|
+ "(`message_id`, `quest_id`, `post_id`, " \
|
||||||
+ "VALUES (%s, %s, %s, %s, %s)",
|
+ "`roll_dice`, `roll_results`, `roll_total`)" \
|
||||||
(message_id, quest_id, post_id, roll_dice, roll_results))
|
+ "VALUES (%s, %s, %s, %s, %s, %s)",
|
||||||
|
(ins))
|
||||||
|
|
||||||
|
|
||||||
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
|
||||||
|
|
20
events.py
20
events.py
|
@ -69,13 +69,25 @@ 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)
|
||||||
roll_results = re.search(r"Rolled (.+)$", roll_msg).group(1)
|
if dice_call[2] and dice_roll != dice_call[1]:
|
||||||
db.insert_quest_roll(
|
return
|
||||||
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"]
|
room = data["room"]
|
||||||
data = {}
|
data = {}
|
||||||
data["post"] = roll_msg + " (" + dice_roll + ")"
|
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_type"] = "dice"
|
||||||
data["post_id"] = dice_call_id
|
data["post_id"] = dice_call_id
|
||||||
emit("update_post", data, room=room)
|
emit("update_post", data, room=room)
|
||||||
|
@ -103,7 +115,7 @@ def handle_dice(data):
|
||||||
msg = f"Rolled {', '.join(map(str, dice))}"
|
msg = f"Rolled {', '.join(map(str, dice))}"
|
||||||
if diceMod:
|
if diceMod:
|
||||||
if diceMod > 0:
|
if diceMod > 0:
|
||||||
msg += " +" + str(diceMod)
|
msg += " + " + str(diceMod)
|
||||||
else:
|
else:
|
||||||
msg += " - " + str(diceMod)[1:]
|
msg += " - " + str(diceMod)[1:]
|
||||||
msg += " = " + str(total)
|
msg += " = " + str(total)
|
||||||
|
|
|
@ -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() {
|
||||||
|
@ -207,11 +207,11 @@
|
||||||
{{ quest_post[3] }}
|
{{ quest_post[3] }}
|
||||||
{% endautoescape %}
|
{% endautoescape %}
|
||||||
{% elif quest_post[2] == "dice" %}
|
{% 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 %}
|
{% for quest_roll in quest_rolls %}
|
||||||
{% if quest_roll[2] == quest_post[0] %}
|
{% if quest_roll[2] == quest_post[0] %}
|
||||||
<div id="questRollId-{{ quest_roll[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>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
4
views.py
4
views.py
|
@ -54,7 +54,7 @@ def quest(quest_title):
|
||||||
quest_id = data[0]
|
quest_id = data[0]
|
||||||
quest_title = data[1]
|
quest_title = data[1]
|
||||||
owner_id = data[3]
|
owner_id = data[3]
|
||||||
dice_call = data[4]
|
dice_call_id = data[4]
|
||||||
quest_posts = db.get_quest_data(quest_id)
|
quest_posts = db.get_quest_data(quest_id)
|
||||||
quest_rolls = db.get_quest_rolls(quest_id)
|
quest_rolls = db.get_quest_rolls(quest_id)
|
||||||
messages = db.get_chat_messages(quest_id)
|
messages = db.get_chat_messages(quest_id)
|
||||||
|
@ -64,7 +64,7 @@ def quest(quest_title):
|
||||||
quest_posts=quest_posts,
|
quest_posts=quest_posts,
|
||||||
quest_rolls=quest_rolls,
|
quest_rolls=quest_rolls,
|
||||||
owner_id=owner_id,
|
owner_id=owner_id,
|
||||||
dice_call=dice_call,
|
dice_call_id=dice_call_id,
|
||||||
room_id=quest_id,
|
room_id=quest_id,
|
||||||
messages=messages)
|
messages=messages)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user