Compare commits

..

No commits in common. "fd9129469899d34e908270937ca7c903bc11e058" and "41b592fcd1e348a6243824f9b84e0474944daea5" have entirely different histories.

5 changed files with 18 additions and 71 deletions

View File

@ -3,14 +3,13 @@
SocketIO events. SocketIO events.
""" """
import time import time
import random
import bleach import bleach
from flask import session from flask import session
from flask_socketio import SocketIO, emit, join_room from flask_socketio import SocketIO, emit, join_room
import tools
import database as db import database as db
import tools
socketio = SocketIO() socketio = SocketIO()
@ -94,18 +93,3 @@ def update_post(data):
post_id = data["post_id"] post_id = data["post_id"]
db.update_quest_post(post_id, post) db.update_quest_post(post_id, post)
emit("update_post", data, room=room) emit("update_post", data, room=room)
@socketio.on('dice_post')
def dice_post(data):
"""
Called when the QM posts a new dice call.
"""
print(data)
room = data["room"]
res = db.get_quest_meta(quest_id=room)
if not res:
return
if session.get("user_id") != res[3]:
return
emit("dice_post", data, room=room)

View File

@ -30,7 +30,6 @@ img {
#questPane { #questPane {
padding-left: 10px; padding-left: 10px;
padding-right: 32%; padding-right: 32%;
min-width: 0;
} }
.questPost { .questPost {
@ -42,11 +41,6 @@ img {
padding-right: 15px; padding-right: 15px;
} }
.questPostData {
word-wrap: break-word;
min-width: 0;
}
#QMPostPane { #QMPostPane {
display: flex; display: flex;
} }

View File

@ -5,7 +5,7 @@
<link rel="stylesheet" type="text/css" href="/static/anonkun.css"> <link rel="stylesheet" type="text/css" href="/static/anonkun.css">
<script> <script>
function toggleHeader() { function toggleHeader() {
let xhr = new XMLHttpRequest(); var xhr = new XMLHttpRequest();
if (document.getElementById('header').style.display == 'initial') { if (document.getElementById('header').style.display == 'initial') {
document.getElementById('header').style.display = 'none'; document.getElementById('header').style.display = 'none';
document.getElementById('headerHidden').style.display = 'initial'; document.getElementById('headerHidden').style.display = 'initial';
@ -23,12 +23,12 @@
</head> </head>
<body> <body>
<ul id="header" class="header" style="{% if session.get("hide_header") == True %}display:none;{% else %}display:initial;{% endif %}"> <ul id="header" class="header" style="{% if session.get("hide_header") == True %}display:none;{% else %}display:initial;{% endif %}">
<li><a onclick="toggleHeader();" href="javascript:void(0);"></a></li> <li><a onclick="toggleHeader();" href="javascript:void(0);">^</a></li>
<li><a href="{{ url_for('.index') }}">Home</a></li> <li><a href="{{ url_for('.index') }}">Home</a></li>
{% block header %}{% endblock %} {% block header %}{% endblock %}
</ul> </ul>
<ul id="headerHidden" class="header" style="{% if session.get("hide_header") == True %}display:initial;{% else %}display:none;{% endif %}"> <ul id="headerHidden" class="header" style="{% if session.get("hide_header") == True %}display:initial;{% else %}display:none;{% endif %}">
<li><a onclick="toggleHeader();" href="javascript:void(0);"></a></li> <li><a onclick="toggleHeader();" href="javascript:void(0);">^</a></li>
</ul> </ul>
<div id="content">{% block content %}{% endblock %} </div> <div id="content">{% block content %}{% endblock %} </div>
</body> </body>

View File

@ -15,32 +15,30 @@
socket.emit('joined', {room: {{ room_id }}}); socket.emit('joined', {room: {{ room_id }}});
}); });
socket.on('message', function(data) { socket.on('message', function(data) {
let date = new Date(data.date * 1000); var date = new Date(data.date * 1000);
let date_str = date.getFullYear() + '-' + padToTwo(date.getMonth()+1) + '-' + padToTwo(date.getDate()) + ' '; var date_str = date.getFullYear() + '-' + padToTwo(date.getMonth()+1) + '-' + padToTwo(date.getDate()) + ' ';
date_str += padToTwo(date.getHours()) + ':' + padToTwo(date.getMinutes()) + ':' + padToTwo(date.getSeconds()); date_str += padToTwo(date.getHours()) + ':' + padToTwo(date.getMinutes()) + ':' + padToTwo(date.getSeconds());
let msg_str = '<div class="messageHeader">\n<span class="messageName">' + data.name + '</span> '; var msg_str = '<div class="messageHeader">\n<span class="messageName">' + data.name + '</span> ';
msg_str += '<span class="messageDate">' + date_str + '</span>\n</div>\n'; msg_str += '<span class="messageDate">' + date_str + '</span>\n</div>\n';
msg_str += '<div class="message">' + data.message + '</div>\n<hr>'; msg_str += '<div class="message">' + data.message + '</div>\n';
let mbox = document.getElementById('chatWindow'); var mbox = document.getElementById('chatWindow');
mbox.innerHTML = mbox.innerHTML + msg_str; mbox.innerHTML = mbox.innerHTML + msg_str;
mbox.scrollTop = mbox.scrollHeight; mbox.scrollTop = mbox.scrollHeight;
}); });
socket.on('new_post', function(data) { socket.on('new_post', function(data) {
let qposts = document.getElementById('questPosts'); var qposts = document.getElementById('questPosts');
qposts.innerHTML = qposts.innerHTML + '<div class="questPost">' + data.post + '</div>'; qposts.innerHTML = qposts.innerHTML + '<div class="questPost">' + data.post + '</div>';
}); });
socket.on('update_post', function(data) { socket.on('update_post', function(data) {
let post_id = data.post_id; var post_id = data.post_id;
document.getElementById('questPostData-' + post_id).innerHTML = data.post; document.getElementById('questPostData-' + post_id).innerHTML = data.post;
}); });
socket.on('dice_post', function(data) { var mtarea = document.getElementById('messageTextArea');
});
let mtarea = document.getElementById('messageTextArea');
mtarea.addEventListener('keypress', function(event) { mtarea.addEventListener('keypress', function(event) {
if (event.key == 'Enter' && !event.shiftKey) { if (event.key == 'Enter' && !event.shiftKey) {
let text = mtarea.value.trim(); var text = mtarea.value.trim();
mtarea.value = ''; mtarea.value = '';
if (text == '') { return; } if (text == '') { return; }
socket.emit('message', {message: text, name: 'Anonymous', room: {{ room_id }}}); socket.emit('message', {message: text, name: 'Anonymous', room: {{ room_id }}});
@ -57,8 +55,8 @@
{% if session.get("user_id") == owner_id %} {% if session.get("user_id") == owner_id %}
<script> <script>
function makePost() { function makePost() {
let qparea = document.getElementById('postTextArea'); var qparea = document.getElementById('postTextArea');
let text = qparea.value.trim(); var text = qparea.value.trim();
qparea.value = ''; qparea.value = '';
if (text == '') { return; } if (text == '') { return; }
socket.emit('new_post', {post: text, room: {{ room_id }}}); socket.emit('new_post', {post: text, room: {{ room_id }}});
@ -72,24 +70,14 @@
function save_post(post_id) { function save_post(post_id) {
document.getElementById('questPostData-' + post_id).contentEditable = 'false'; document.getElementById('questPostData-' + post_id).contentEditable = 'false';
document.getElementById('questPostData-' + post_id).style.border = null; document.getElementById('questPostData-' + post_id).style.border = null;
let text = document.getElementById('questPostData-' + post_id).innerHTML; var text = document.getElementById('questPostData-' + post_id).innerHTML;
socket.emit('update_post', {post_id: post_id, post: text, room: {{ room_id }}}); socket.emit('update_post', {post_id: post_id, post: text, room: {{ room_id }}});
document.getElementById('savePost-' + post_id).style.display = 'none'; document.getElementById('savePost-' + post_id).style.display = 'none';
} }
function dice_post() {
let formData = new FormData(document.getElementById('QMDicePostForm'));
formData.append('room', {{ room_id }});
let obj = {};
formData.forEach(function(value, key) {
obj[key] = value;
});
socket.emit('dice_post', obj);
document.getElementById('QMDicePostForm').reset();
}
</script> </script>
<script> <script>
function openPostTab(event, modeName) { function openPostTab(event, modeName) {
let i, QMPostTabContent, QMPostTab; var i, QMPostTabContent, QMPostTab;
QMPostTabContent = document.getElementsByClassName("QMPostTabContent"); QMPostTabContent = document.getElementsByClassName("QMPostTabContent");
for (i = 0; i < QMPostTabContent.length; i++) { for (i = 0; i < QMPostTabContent.length; i++) {
@ -148,24 +136,7 @@
<input type="submit" name="newPost" value="Post" onclick="makePost();"/> <input type="submit" name="newPost" value="Post" onclick="makePost();"/>
</div> </div>
<div id="QMPostDice" class="QMPostTabContent" style="display:none;"> <div id="QMPostDice" class="QMPostTabContent" style="display:none;">
Dice for the dice god.<br /> Dice for the dice god.
<form id="QMDicePostForm" action="javascript:void(0);" onsubmit="dice_post();">
Dice: <input type="number" name="diceNum" min="1" max="99"/>
d <input type="number" name="diceSides" min="1" max="99"/>
±<input type="number" name="diceMod" min="-999" max="999"/>
<input type="checkbox" name="diceStrict"/>
<span class="tooltip" title="Only take matching rolls.">Strict</span><br />
<input type="checkbox" onclick="document.getElementById('diceChal').disabled=!this.checked;"/>
<span class="tooltip" title="Dice challenge">DC:</span>
<input type="number" name="diceChal" id="diceChal" min="1" max="99" disabled/><br />
<input type="checkbox" onclick="document.getElementById('diceRolls').disabled=!this.checked;"/>
<span class="tooltip" title="Automatically close the dice call after this many rolls have been made.">Rolls Taken:</span>
<input type="number" name="diceRolls" id="diceRolls" min="1" max="99" disabled/><br />
<input type="checkbox" onclick="document.getElementById('diceBest').disabled=!this.checked;"/>
<span class="tooltip" title="Pick out the N highest rolls after the dice call has been closed. This should be lower than the number of rolls taken.">Best:</span>
<input type="number" name="diceBest" id="diceBest" min="1" max="99" disabled/><br />
<input type="submit" name="submit" value="Roll 'em"/>
</form>
</div> </div>
<div id="QMPostPoll" class="QMPostTabContent" style="display:none;"> <div id="QMPostPoll" class="QMPostTabContent" style="display:none;">
The polls are rigged. The polls are rigged.
@ -186,7 +157,6 @@
</div> </div>
<div class="messageMessage">{{ message[4] }}</div> <div class="messageMessage">{{ message[4] }}</div>
</div> </div>
<hr>
{% endfor %} {% endfor %}
{% endautoescape %} {% endautoescape %}
</div> </div>

View File

@ -4,7 +4,6 @@ Miscellaneous tools and help functions.
""" """
import os import os
import re import re
import urllib
import hashlib import hashlib
import magic import magic