yee #1
@ -1,4 +1,4 @@
|
|||||||
import io
|
import time
|
||||||
import re
|
import re
|
||||||
from typing import TYPE_CHECKING, TypeVar
|
from typing import TYPE_CHECKING, TypeVar
|
||||||
|
|
||||||
@ -8,27 +8,47 @@ else:
|
|||||||
IcaNewMessage = TypeVar("NewMessage")
|
IcaNewMessage = TypeVar("NewMessage")
|
||||||
IcaClient = TypeVar("IcaClient")
|
IcaClient = TypeVar("IcaClient")
|
||||||
|
|
||||||
|
EMPTY_VOTE = {i: [] for i in range(0, 24)}
|
||||||
def on_ica_message(msg: IcaNewMessage, client: IcaClient) -> None:
|
VOTE = {}
|
||||||
if (not (msg.is_from_self or msg.is_reply)) and (msg.content.startswith("/hyp") or "any hyp" in msg.content):
|
|
||||||
hypvote(msg)
|
|
||||||
|
|
||||||
|
|
||||||
vote = dict([(i, []) for i in range(0,24)]
|
def fmt_vote(room_id) -> str:
|
||||||
|
global VOTE
|
||||||
|
if room_id not in VOTE:
|
||||||
|
VOTE[room_id] = EMPTY_VOTE.copy()
|
||||||
|
return "|".join(
|
||||||
|
f"{x}{VOTE[room_id][x] if VOTE[room_id][x] else ""}" for x in VOTE[room_id]
|
||||||
|
)
|
||||||
|
|
||||||
def hypvote(msg):
|
|
||||||
arg = re.match("/hyp(.+)", msg.content + " ").group(1)
|
def hypvote(msg: IcaNewMessage, client: IcaClient):
|
||||||
|
global VOTE
|
||||||
|
matchs = re.match("/hyp (.+)", msg.content + " ")
|
||||||
|
if matchs:
|
||||||
|
arg = matchs.group(1).split(" ")
|
||||||
|
else:
|
||||||
|
return
|
||||||
|
if msg.room_id not in VOTE:
|
||||||
|
VOTE[msg.room_id] = EMPTY_VOTE.copy()
|
||||||
if arg[0] == "vote":
|
if arg[0] == "vote":
|
||||||
map(lambda x: vote[int(x) % 24] += msg.sender, arg[1:])
|
for x in arg[1:]:
|
||||||
else if arg[0] == "unvote":
|
if x.isdigit() and 0 <= int(x) < 24:
|
||||||
map(lambda x: vote[int(x) % 24].remove(msg.sender), arg[1:])
|
if msg.sender_id in VOTE[msg.room_id][int(x) % 24]:
|
||||||
else if arg[0] == "clear":
|
continue
|
||||||
vote = dict([(i, []) for i in range(0,24)]
|
VOTE[msg.room_id][int(x) % 24].append(msg.sender_id)
|
||||||
else if arg == [] or arg[0] == "ls" or "any hyp"in msg.content:
|
elif arg[0] == "unvote":
|
||||||
res = "\n".join([f"{x}\t{vote[x]}" for x in vote])
|
for x in arg[1:]:
|
||||||
msg.reply_with(res)
|
if x.isdigit() and 0 <= int(x) < 24:
|
||||||
else if arg[0] == "help":
|
if msg.sender_id in VOTE[int(x) % 24]:
|
||||||
msg.reply_with("""NAME
|
VOTE[msg.room_id][int(x) % 24].remove(msg.sender_id)
|
||||||
|
elif arg[0] == "clear":
|
||||||
|
VOTE[msg.room_id] = EMPTY_VOTE.copy()
|
||||||
|
elif arg == [] or arg[0] == "ls":
|
||||||
|
res = fmt_vote(msg.room_id)
|
||||||
|
reply = msg.reply_with(res)
|
||||||
|
client.send_message(reply)
|
||||||
|
elif arg[0] == "help":
|
||||||
|
reply = msg.reply_with("""NAME
|
||||||
/hyp - 计划时间,高效开黑
|
/hyp - 计划时间,高效开黑
|
||||||
SYNOPSIS
|
SYNOPSIS
|
||||||
/hyp [command] [args]
|
/hyp [command] [args]
|
||||||
@ -45,4 +65,11 @@ OPTIONS
|
|||||||
show this help
|
show this help
|
||||||
AUTHOR
|
AUTHOR
|
||||||
dongdigua
|
dongdigua
|
||||||
|
shenjack(bugfixs)
|
||||||
""")
|
""")
|
||||||
|
client.send_message(reply)
|
||||||
|
|
||||||
|
|
||||||
|
def on_ica_message(msg: IcaNewMessage, client: IcaClient) -> None:
|
||||||
|
if (not (msg.is_from_self or msg.is_reply)) and msg.content.startswith("/hyp"):
|
||||||
|
hypvote(msg, client)
|
||||||
|
Loading…
Reference in New Issue
Block a user