diff --git a/database.py b/database.py index c004598..e06e985 100644 --- a/database.py +++ b/database.py @@ -136,7 +136,11 @@ def insert_quest_post(quest_id, post, timestamp): """ _DB.execute( "INSERT INTO `quest_data` (`quest_id`, `post`, `timestamp`) " \ - "VALUES (%s, %s, %s)", (quest_id, post, timestamp)) + + "VALUES (%s, %s, %s)", (quest_id, post, timestamp)) + post_id = _DB.execute( + "SELECT `post_id` FROM `quest_data` WHERE `quest_id` = %s " \ + + "ORDER BY `post_id` DESC", (quest_id,)).fetchone()[0] + return post_id def get_quest_meta(quest_id=None, ident_title=None): diff --git a/events.py b/events.py index 3ebba10..6d5950a 100644 --- a/events.py +++ b/events.py @@ -69,7 +69,9 @@ def new_post(data): post = post.replace("\n", "
") post = tools.handle_img(post) data["post"] = [post] - db.insert_quest_post(room, post, int(time.time())) + data["date"] = int(time.time()) + post_id = db.insert_quest_post(room, post, data["date"]) + data["post_id"] = post_id emit("new_post", data, room=room) @@ -96,8 +98,8 @@ def update_post(data): emit("update_post", data, room=room) -@socketio.on('dice_post') -def dice_post(data): +@socketio.on("dice_post") +def dice_(data): """ Called when the QM posts a new dice call. """ @@ -108,4 +110,9 @@ def dice_post(data): return if session.get("user_id") != res[3]: return + + date = int(time.time()) + data["date"] = date + data["post_id"] = 0 + emit("dice_post", data, room=room) diff --git a/templates/quest.html b/templates/quest.html index 05133a7..05b8dea 100644 --- a/templates/quest.html +++ b/templates/quest.html @@ -15,13 +15,9 @@ socket.emit('joined', {room: {{ room_id }}}); }); socket.on('message', function(data) { - let date = new Date(data.date * 1000); - let date_str = date.getFullYear() + '-' + padToTwo(date.getMonth()+1) + '-' + padToTwo(date.getDate()) + ' '; - date_str += padToTwo(date.getHours()) + ':' + padToTwo(date.getMinutes()) + ':' + padToTwo(date.getSeconds()); - - let msg_str = '
\n' + data.name + ' '; - msg_str += '' + date_str + '\n
\n'; - msg_str += '
' + data.message + '
\n
'; + let msg_str = '
' + data.name + ' '; + msg_str += '' + strftime(data.date) + '
'; + msg_str += '
' + data.message + '

'; let mbox = document.getElementById('chatWindow'); mbox.innerHTML = mbox.innerHTML + msg_str; @@ -29,13 +25,30 @@ }); socket.on('new_post', function(data) { let qposts = document.getElementById('questPosts'); - qposts.innerHTML = qposts.innerHTML + '
' + data.post + '
'; + let post_str = '
' + strftime(data.date); + {% if session.get("user_id") == owner_id %} + post_str += '
Edit'; + post_str += ''; + {% endif %} + post_str += '
' + data.post + '
'; + qposts.innerHTML = qposts.innerHTML + post_str; }); socket.on('update_post', function(data) { let post_id = data.post_id; document.getElementById('questPostData-' + post_id).innerHTML = data.post; }); socket.on('dice_post', function(data) { + let qposts = document.getElementById('questPosts'); + let post_str = '
' + strftime(data.date) + "
"; + post_str += '
' + post_str += "

Roll " + data.diceNum + "d" + data.diceSides; + if (data.diceMod > 0) { post_str += "+"; } + if (data.diceMod != 0) { post_str += data.diceMod; } + if (data.diceChal) { post_str += " vs DC" + data.diceChal; } + post_str += "


"; + post_str += "
"; + + qposts.innerHTML = qposts.innerHTML + post_str; }); let mtarea = document.getElementById('messageTextArea'); mtarea.addEventListener('keypress', function(event) { @@ -53,6 +66,12 @@ if (number<=99) { number = ("0"+number).slice(-2); } return number; } + function strftime(date) { + date = new Date(date * 1000); + let date_str = date.getFullYear() + '-' + padToTwo(date.getMonth()+1) + '-' + padToTwo(date.getDate()) + ' '; + date_str += padToTwo(date.getHours()) + ':' + padToTwo(date.getMinutes()) + ':' + padToTwo(date.getSeconds()); + return date_str; + } {% if session.get("user_id") == owner_id %}