zhenxun_bot/plugins/sign_in/__init__.py

92 lines
3.2 KiB
Python
Raw Normal View History

2021-07-30 21:21:51 +08:00
from .group_user_checkin import (
group_user_check_in,
group_user_check,
group_impression_rank,
impression_rank,
)
2021-05-20 19:25:51 +08:00
from nonebot.typing import T_State
2021-06-15 10:57:08 +08:00
from nonebot.adapters.cqhttp import Bot, GroupMessageEvent
2021-05-20 19:25:51 +08:00
from nonebot.adapters.cqhttp.permission import GROUP
2021-07-30 21:21:51 +08:00
from utils.message_builder import image
2021-06-30 19:50:55 +08:00
from nonebot import on_command
from utils.utils import get_message_text
from pathlib import Path
from configs.path_config import DATA_PATH
2021-07-30 21:21:51 +08:00
2021-06-30 19:50:55 +08:00
try:
import ujson as json
except ModuleNotFoundError:
import json
2021-05-20 19:25:51 +08:00
2021-07-30 21:21:51 +08:00
__plugin_name__ = "签到"
2021-05-20 19:25:51 +08:00
__plugin_usage__ = (
2021-07-30 21:21:51 +08:00
"用法:\n"
"对我说 “签到” 来签到\n"
"“我的签到” 来获取历史签到信息\n"
"“好感度排行” 来查看当前好感度前十的伙伴\n"
"/ 签到时有 3% 概率 * 2 /"
2021-05-20 19:25:51 +08:00
)
2021-07-30 21:21:51 +08:00
_file = Path(f"{DATA_PATH}/not_show_sign_rank_user.json")
2021-06-30 19:50:55 +08:00
try:
2021-07-30 21:21:51 +08:00
data = json.load(open(_file, "r", encoding="utf8"))
2021-06-30 19:50:55 +08:00
except (FileNotFoundError, ValueError, TypeError):
2021-07-30 21:21:51 +08:00
data = {"0": []}
2021-05-20 19:25:51 +08:00
2021-06-30 19:50:55 +08:00
sign = on_command("签到", priority=5, permission=GROUP, block=True)
2021-07-30 21:21:51 +08:00
my_sign = on_command(
cmd="我的签到", aliases={"好感度"}, priority=5, permission=GROUP, block=True
)
sign_rank = on_command(
cmd="积分排行",
aliases={"好感度排行", "签到排行", "积分排行", "好感排行", "好感度排名,签到排名,积分排名"},
priority=5,
permission=GROUP,
block=True,
)
total_sign_rank = on_command(
"签到总排行", aliases={"好感度总排行", "好感度总榜", "签到总榜"}, priority=5, block=True
)
2021-05-20 19:25:51 +08:00
@sign.handle()
async def _(bot: Bot, event: GroupMessageEvent, state: T_State):
await sign.send(
await group_user_check_in(event.user_id, event.group_id),
at_sender=True,
)
@my_sign.handle()
async def _(bot: Bot, event: GroupMessageEvent, state: T_State):
await my_sign.send(
await group_user_check(event.user_id, event.group_id),
at_sender=True,
)
2021-06-30 19:50:55 +08:00
@sign_rank.handle()
2021-05-20 19:25:51 +08:00
async def _(bot: Bot, event: GroupMessageEvent, state: T_State):
2021-07-30 21:21:51 +08:00
await sign_rank.send(await group_impression_rank(event.group_id))
2021-06-30 19:50:55 +08:00
@total_sign_rank.handle()
async def _(bot: Bot, event: GroupMessageEvent, state: T_State):
msg = get_message_text(event.json())
if not msg:
2021-07-30 21:21:51 +08:00
await total_sign_rank.send("请稍等..正在整理数据...")
2021-06-30 19:50:55 +08:00
await total_sign_rank.send(image(b64=await impression_rank(0, data)))
2021-07-30 21:21:51 +08:00
elif msg in ["屏蔽我"]:
if event.user_id in data["0"]:
await total_sign_rank.finish("您已经在屏蔽名单中了,请勿重复添加!", at_sender=True)
data["0"].append(event.user_id)
await total_sign_rank.send("设置成功,您不会出现在签到总榜中!", at_sender=True)
elif msg in ["显示我"]:
if event.user_id not in data["0"]:
await total_sign_rank.finish("您不在屏蔽名单中!", at_sender=True)
data["0"].remove(event.user_id)
await total_sign_rank.send("设置成功,签到总榜将会显示您的头像名称以及好感度!", at_sender=True)
with open(_file, "w", encoding="utf8") as f:
2021-06-30 19:50:55 +08:00
json.dump(data, f, ensure_ascii=False, indent=4)