From e8c4ed8c60cf90d491b14304018dc4282497859b Mon Sep 17 00:00:00 2001 From: shenjack <3695888@qq.com> Date: Fri, 9 Aug 2024 18:33:37 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BA=86=E4=B8=80=E4=BA=9B?= =?UTF-8?q?=E9=97=AE=E9=A2=98=EF=BC=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/hyp_vote.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/plugins/hyp_vote.py b/plugins/hyp_vote.py index b030d6e..a4263fe 100644 --- a/plugins/hyp_vote.py +++ b/plugins/hyp_vote.py @@ -10,10 +10,10 @@ else: IcaClient = TypeVar("IcaClient") -def gen_room() -> dict[int, list[int]]: - return {i: [] for i in range(0, 24)} +def gen_room() -> dict[int, dict[int, str]]: + return {i: {} for i in range(0, 24)} -VOTE = {} +VOTE: dict[int, dict[int, str]] = {} def fmt_vote(room_id) -> str: @@ -39,16 +39,20 @@ def hypvote(msg: IcaNewMessage, client: IcaClient): if x.isdigit() and 0 <= int(x) < 24: if msg.sender_id in VOTE[msg.room_id][int(x) % 24]: continue - VOTE[msg.room_id][int(x) % 24].append(msg.sender_id) + VOTE[msg.room_id][int(x) % 24][msg.sender_id] = msg.sender_name elif arg[0] == "unvote": for x in arg[1:]: if x.isdigit() and 0 <= int(x) < 24: if msg.sender_id in VOTE[msg.room_id][int(x) % 24]: - VOTE[msg.room_id][int(x) % 24].remove(msg.sender_id) + VOTE[msg.room_id][int(x) % 24][msg.sender_id] = None elif arg[0] == "clear": VOTE[msg.room_id] = gen_room() elif arg[0] == "view": - ... + replys = "\n".join( + f"{x}: {','.join(VOTE[msg.room_id][int(x) % 24].values())}" for x in arg[1:] if x.isdigit() + ) + reply = msg.reply_with(replys) + client.send_message(reply) elif arg == [] or arg[0] == "ls": res = fmt_vote(msg.room_id) reply = msg.reply_with(res) @@ -68,7 +72,7 @@ OPTIONS ls list voted time, equivalent to empty view - + view who vote for the time help show this help AUTHOR