Control socket: show all chat messages

このコミットが含まれているのは:
n9k 2022-08-12 05:18:23 +00:00
コミット 3fca390a30
2個のファイルの変更16行の追加6行の削除

ファイルの表示

@ -2,6 +2,9 @@
# SPDX-License-Identifier: AGPL-3.0-or-later
import itertools
import json
from quart import current_app
from anonstream.chat import delete_chat_messages
from anonstream.control.exceptions import CommandFailed
@ -10,6 +13,8 @@ from anonstream.control.spec.common import Str, End, Args, ArgsJsonString, ArgsU
from anonstream.control.spec.utils import get_item, json_dumps_contiguous
from anonstream.chat import add_chat_message, Rejected
MESSAGES = current_app.messages
class ArgsSeqs(Args):
def consume(self, words, index):
seqs = []
@ -33,13 +38,12 @@ class ArgsSeqs(Args):
async def cmd_chat_help():
normal = ['chat', 'help']
response = (
'Usage: chat delete SEQS\n'
'Usage: chat {show | delete SEQS | add USER NONCE COMMENT}\n'
'Commands:\n'
#' chat show [MESSAGES]...........show chat messages\n'
' chat show......................show all chat messages\n'
' chat delete SEQS...............delete chat messages\n'
' chat add USER NONCE COMMENT....add chat message\n'
'Definitions:\n'
#' MESSAGES...................undefined\n'
' SEQS.......................=SEQ [SEQ...]\n'
' SEQ........................a chat message\'s seq, base-10 integer\n'
' USER.......................={token TOKEN | hash HASH}\n'
@ -50,6 +54,11 @@ async def cmd_chat_help():
)
return normal, response
async def cmd_chat_show():
normal = ['chat', 'show']
response = json.dumps(tuple(MESSAGES), separators=(',', ':')) + '\n'
return normal, response
async def cmd_chat_delete(*seqs):
delete_chat_messages(seqs)
normal = ['chat', 'delete', *map(str, seqs)]
@ -74,6 +83,7 @@ async def cmd_chat_add(user, nonce, comment):
SPEC = Str({
None: End(cmd_chat_help),
'help': End(cmd_chat_help),
'show': End(cmd_chat_show),
'delete': ArgsSeqs(End(cmd_chat_delete)),
'add': ArgsUser(ArgsJsonString(ArgsJsonString(End(cmd_chat_add)))),
})

ファイルの表示

@ -19,9 +19,9 @@ async def cmd_help():
' user eyes USER [show]..........show a list of active video responses\n'
' user eyes USER delete EYES_ID..end a video response\n'
' user add VERIFIED TOKEN........add new user\n'
#' chat show MESSAGES.............show a list of messages\n'
' chat delete SEQS...............delete a set of messages\n'
' chat add USER NONCE COMMENT....add chat message\n'
' chat show......................show a list of all chat messages\n'
' chat delete SEQS...............delete a set of chat messages\n'
' chat add USER NONCE COMMENT....add a chat message\n'
' allowedness [show].............show the current allowedness\n'
' allowedness setdefault BOOLEAN.set the default allowedness\n'
' allowedness add SET STRING.....add to the blacklist/whitelist\n'