diff --git a/quest/events.py b/quest/events.py
index ac18b23..ea92787 100644
--- a/quest/events.py
+++ b/quest/events.py
@@ -12,6 +12,7 @@ import bleach
from django.utils.timezone import localtime
from quest.models import Message, Quest, Post
+from quest.forms import DiceCallForm
def message(socket, data):
"""
@@ -93,13 +94,14 @@ def text_post(socket, data):
"""
Called when the QM creates a new text post.
"""
+ # TODO: security
quest_id = data.get('quest_id')
- text = data.get('text')
+ post_text = data.get('text')
page_num = data.get('page_num')
# cleaning
- text = bleach.clean(text.strip())
- text = text.replace("\n", "
")
+ post_text = bleach.clean(post_text.strip())
+ post_text = text.replace("\n", "
")
# handle image
@@ -107,17 +109,46 @@ def text_post(socket, data):
quest=Quest.objects.get(id=quest_id),
page_num=page_num,
post_type='text',
- post_text=text)
+ post_text=post_text)
p.save()
data = {}
- data['text'] = text
+ data['post_text'] = post_text
data['post_type'] = 'text'
data['date'] = localtime(p.timestamp).strftime('%Y-%m-%d %H:%M')
data['post_id'] = p.id
socket.send('new_post', data)
+def dice_post(socket, data):
+ """
+ Called when the QM makes a new dice post.
+ """
+ quest_id = data.get('quest_id')
+ page_num = data.get('page_num')
+ form = DiceCallForm(data)
+ if not form.is_valid():
+ return # error message?
+
+ dice_roll = str(form.cleaned_data['diceNum']) + "d"
+ dice_roll += str(form.cleaned_data['diceSides'])
+ if form.cleaned_data['diceMod']:
+ if form.cleaned_data['diceMod'] > 0:
+ dice_roll += "+"
+ dice_roll += str(form.cleaned_data['diceMod'])
+
+ post_text = "Roll " + dice_roll
+ if form.cleaned_data['diceChal']:
+ post_text += " vs DC" + str(form.cleaned_data['diceChal'])
+
+ data = {}
+ data['post_text'] = post_text
+ data['post_type'] = 'dice'
+ data['date'] = int(time.time())
+ data['post_id'] = 1
+ socket.send('new_post', data)
+
+
events = {}
for obj in dir():
if type(locals()[obj]) == types.FunctionType:
diff --git a/quest/forms.py b/quest/forms.py
new file mode 100644
index 0000000..53f8455
--- /dev/null
+++ b/quest/forms.py
@@ -0,0 +1,19 @@
+#!/usr/bin/env python3
+"""
+Form(s) for the quest page.
+"""
+from django import forms
+
+class DiceCallForm(forms.Form):
+ """
+ The form for the QM making dice calls.
+ """
+ diceNum = forms.IntegerField(min_value=1, max_value=99)
+ diceSides = forms.IntegerField(min_value=1, max_value=99)
+ diceMod = forms.IntegerField(min_value=-999, max_value=999,
+ required=False)
+ diceChal = forms.IntegerField(min_value=1, max_value=99,
+ required=False)
+ diceRollsTaken = forms.IntegerField(min_value=1, max_value=99,
+ required=False)
+ diceStrict = forms.BooleanField(required=False)
diff --git a/quest/static/quest.css b/quest/static/quest.css
index 9b44446..768a5d7 100644
--- a/quest/static/quest.css
+++ b/quest/static/quest.css
@@ -15,8 +15,7 @@ h3 {
#questPane {
padding-left: 5%;
- padding-right: 35%;
- width: 100%;
+ width: 65%;
}
.questPost {
diff --git a/quest/static/quest.js b/quest/static/quest.js
index 01bd9ca..e551b38 100644
--- a/quest/static/quest.js
+++ b/quest/static/quest.js
@@ -55,11 +55,11 @@ socket.events['new_post'] = function(data) {
post_str += '