diff --git a/README.md b/README.md index 73826a7..06d715a 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,7 @@ titivillus=# \q 2. Walk the dinosaur 3. Set `STATIC_ROOT` under `settings.py` appropriately 4. Run `python manage.py collectstatic` +5. Create \[super\]user named `Server` and set id in settings.py ## Usage `gunicorn -b localhost:5100 -e SCRIPT_NAME=/titivillus titivillus.wsgi` diff --git a/quest/events.py b/quest/events.py index 2f1415a..c56db70 100644 --- a/quest/events.py +++ b/quest/events.py @@ -11,6 +11,7 @@ import types import random import bleach +from django.conf import settings from django.db import IntegrityError from django.utils.timezone import localtime from django.urls import reverse @@ -18,6 +19,7 @@ from django.urls import reverse from quest.models import * from quest.tools import handle_img from quest.forms import DiceCallForm, PollForm +from user.models import User def message(socket, data): """ @@ -172,6 +174,21 @@ def text_post(socket, data): data['post_id'] = p.id socket.send('new_post', data) + server = User.objects.get(id=settings.SERVER_USER_ID) + m = Message( + quest=quest, + user=server, + message=f"{quest.owner.username} made a new post!", + ) + m.save() + data = {} + data['message_id'] = m.id + data['message'] = m.message + data['date'] = int(time.time()) + data['name'] = server.username + data['anonymize'] = False + socket.send('message', data) + def dice_post(socket, data): """ @@ -226,6 +243,21 @@ def dice_post(socket, data): data['date'] = localtime(p.timestamp).strftime('%Y-%m-%d %H:%M') socket.send('new_post', data) + server = User.objects.get(id=settings.SERVER_USER_ID) + m = Message( + quest=quest, + user=server, + message=f"{quest.owner.username} made a new dice call!", + ) + m.save() + data = {} + data['message_id'] = m.id + data['message'] = m.message + data['date'] = int(time.time()) + data['name'] = server.username + data['anonymize'] = False + socket.send('message', data) + def poll_post(socket, data): """ @@ -269,6 +301,21 @@ def poll_post(socket, data): data['options'] = [(o.id, o.text) for o in options] socket.send('new_post', data) + server = User.objects.get(id=settings.SERVER_USER_ID) + m = Message( + quest=quest, + user=server, + message=f"{quest.owner.username} made a new poll!", + ) + m.save() + data = {} + data['message_id'] = m.id + data['message'] = m.message + data['date'] = int(time.time()) + data['name'] = server.username + data['anonymize'] = False + socket.send('message', data) + def edit_post(socket, data): """ @@ -454,6 +501,21 @@ def new_page(socket, data): data['url'] = reverse('quest:quest', args=[socket.quest_id, p.page_num]) socket.send('new_page', data) + server = User.objects.get(id=settings.SERVER_USER_ID) + m = Message( + quest=quest, + user=server, + message=f"{quest.owner.username} started a new page!", + ) + m.save() + data = {} + data['message_id'] = m.id + data['message'] = m.message + data['date'] = int(time.time()) + data['name'] = server.username + data['anonymize'] = False + socket.send('message', data) + events = {} for obj in dir(): diff --git a/quest/jinja2/quest/chat.html b/quest/jinja2/quest/chat.html index fe505c8..c879a36 100644 --- a/quest/jinja2/quest/chat.html +++ b/quest/jinja2/quest/chat.html @@ -5,10 +5,11 @@ {% for message in chat_messages %}