版本更新

This commit is contained in:
HibiKier
2024-10-20 21:11:16 +08:00
parent 4e33bf3a50
commit d594d17bf6
253 changed files with 34987 additions and 2241 deletions
+52 -43
View File
@@ -1,9 +1,10 @@
from nonebot.adapters import Bot, Event
from nonebot_plugin_uninfo import Uninfo
from nonebot.plugin import PluginMetadata
from nonebot_plugin_session import EventSession
from nonebot_plugin_userinfo import UserInfo, EventUserInfo
from nonebot_plugin_alconna import (
Args,
Match,
Query,
Option,
UniMsg,
@@ -17,6 +18,7 @@ from nonebot_plugin_alconna import (
)
from zhenxun.services.log import logger
from zhenxun.utils.depends import UserName
from zhenxun.utils.message import MessageUtils
from zhenxun.utils.exception import GoodsNotFound
from zhenxun.utils.enum import BlockType, PluginType
@@ -53,8 +55,8 @@ _matcher = on_alconna(
Option("--all", action=store_true),
Subcommand("my-cost", help_text="我的金币"),
Subcommand("my-props", help_text="我的道具"),
Subcommand("buy", Args["name", str]["num", int, 1], help_text="购买道具"),
Subcommand("use", Args["name", str]["num?", int, 1], help_text="使用道具"),
Subcommand("buy", Args["name?", str]["num?", int], help_text="购买道具"),
Subcommand("use", Args["name?", str]["num?", int], help_text="使用道具"),
Subcommand("gold-list", Args["num?", int], help_text="金币排行"),
),
priority=5,
@@ -76,16 +78,16 @@ _matcher.shortcut(
)
_matcher.shortcut(
"购买道具",
"购买道具(?P<name>.*?)",
command="商店",
arguments=["buy", "{%0}"],
arguments=["buy", "{name}"],
prefix=True,
)
_matcher.shortcut(
"使用道具",
"使用道具(?P<name>.*?)",
command="商店",
arguments=["use", "{%0}"],
arguments=["use", "{name}"],
prefix=True,
)
@@ -122,14 +124,12 @@ async def _(session: EventSession, arparma: Arparma):
@_matcher.assign("my-props")
async def _(
session: EventSession, arparma: Arparma, user_info: UserInfo = EventUserInfo()
):
async def _(session: EventSession, arparma: Arparma, nickname: str = UserName()):
if session.id1:
logger.info("查看道具", arparma.header_result, session=session)
if image := await ShopManage.my_props(
session.id1,
user_info.user_displayname or user_info.user_name,
nickname,
session.platform,
):
await MessageUtils.build_message(image.pic2bytes()).finish(reply_to=True)
@@ -139,17 +139,23 @@ async def _(
@_matcher.assign("buy")
async def _(session: EventSession, arparma: Arparma, name: str, num: int):
if session.id1:
logger.info(
f"购买道具 {name}, 数量: {num}",
arparma.header_result,
session=session,
)
result = await ShopManage.buy_prop(session.id1, name, num, session.platform)
await MessageUtils.build_message(result).send(reply_to=True)
else:
await MessageUtils.build_message("用户id为空...").send(reply_to=True)
async def _(
session: Uninfo,
arparma: Arparma,
name: Match[str],
num: Query[int] = AlconnaQuery("num", 1),
):
if not name.available:
await MessageUtils.build_message(
"请在指令后跟需要购买的道具名称或id..."
).finish(reply_to=True)
logger.info(
f"购买道具 {name}, 数量: {num}",
arparma.header_result,
session=session,
)
result = await ShopManage.buy_prop(session.user.id, name.result, num.result)
await MessageUtils.build_message(result).send(reply_to=True)
@_matcher.assign("use")
@@ -159,11 +165,17 @@ async def _(
message: UniMsg,
session: EventSession,
arparma: Arparma,
name: str,
num: int,
name: Match[str],
num: Query[int] = AlconnaQuery("num", 1),
):
if not name.available:
await MessageUtils.build_message(
"请在指令后跟需要使用的道具名称或id..."
).finish(reply_to=True)
try:
result = await ShopManage.use(bot, event, session, message, name, num, "")
result = await ShopManage.use(
bot, event, session, message, name.result, num.result, ""
)
logger.info(
f"使用道具 {name}, 数量: {num}", arparma.header_result, session=session
)
@@ -179,24 +191,21 @@ async def _(
@_matcher.assign("gold-list")
async def _(
session: EventSession, arparma: Arparma, num: Query[int] = AlconnaQuery("num", 10)
session: Uninfo, arparma: Arparma, num: Query[int] = AlconnaQuery("num", 10)
):
if num.result > 50:
await MessageUtils.build_message("排行榜人数不能超过50哦...").finish()
if session.id1:
gid = session.id3 or session.id2
if not arparma.find("all") and not gid:
await MessageUtils.build_message(
"私聊中无法查看 '金币排行',请发送 '金币总排行'"
).finish()
if arparma.find("all"):
gid = None
result = await gold_rank(session.id1, gid, num.result, session.platform)
logger.info(
"查看金币排行",
arparma.header_result,
session=session,
)
await MessageUtils.build_message(result).send(reply_to=True)
else:
await MessageUtils.build_message("用户id为空...").send(reply_to=True)
gid = session.group.id if session.group else None
if not arparma.find("all") and not gid:
await MessageUtils.build_message(
"私聊中无法查看 '金币排行',请发送 '金币总排行'"
).finish()
if arparma.find("all"):
gid = None
result = await gold_rank(session, gid, num.result)
logger.info(
"查看金币排行",
arparma.header_result,
session=session,
)
await MessageUtils.build_message(result).send(reply_to=True)
+23 -10
View File
@@ -6,6 +6,7 @@ from types import MappingProxyType
from collections.abc import Callable
from nonebot.adapters import Bot, Event
from nonebot_plugin_uninfo import Uninfo
from pydantic import BaseModel, create_model
from nonebot_plugin_session import EventSession
from nonebot_plugin_alconna import UniMsg, UniMessage
@@ -58,9 +59,9 @@ class Goods(BaseModel):
class ShopParam(BaseModel):
goods_name: str
"""商品名称"""
user_id: int
user_id: str
"""用户id"""
group_id: int
group_id: str | None
"""群聊id"""
bot: Any
"""bot"""
@@ -80,16 +81,21 @@ class ShopParam(BaseModel):
"""UniMessage"""
async def gold_rank(user_id: str, group_id: str | None, num: int, platform: str):
async def gold_rank(
session: Uninfo, group_id: str | None, num: int
) -> BuildImage | str:
query = UserConsole
if group_id:
uid_list = await GroupInfoUser.filter(group_id=group_id).values_list(
"user_id", flat=True
)
query = query.filter(user_id__in=uid_list)
if uid_list:
query = query.filter(user_id__in=uid_list)
user_list = await query.annotate().order_by("-gold").values_list("user_id", "gold")
if not user_list:
return "当前还没有人拥有金币哦..."
user_id_list = [user[0] for user in user_list]
index = user_id_list.index(user_id) + 1
index = user_id_list.index(session.user.id) + 1
user_list = user_list[:num] if num < len(user_list) else user_list
friend_user = await FriendUser.filter(user_id__in=user_id_list).values_list(
"user_id", "user_name"
@@ -103,8 +109,11 @@ async def gold_rank(user_id: str, group_id: str | None, num: int, platform: str)
uid2name[g[0]] = g[1]
column_name = ["排名", "-", "名称", "金币", "平台"]
data_list = []
platform = PlatformUtils.get_platform(session)
for i, user in enumerate(user_list):
ava_bytes = await PlatformUtils.get_user_avatar(user[0], platform)
ava_bytes = await PlatformUtils.get_user_avatar(
user[0], platform, session.self_id
)
data_list.append(
[
f"{i+1}",
@@ -294,9 +303,12 @@ class ShopManage:
str | MessageFactory | None: 使用完成后返回信息
"""
if goods_name.isdigit():
user = await UserConsole.get_user(user_id=session.id1) # type: ignore
uuid = list(user.props.keys())[int(goods_name)]
goods_info = await GoodsInfo.get_or_none(uuid=uuid)
try:
user = await UserConsole.get_user(user_id=session.id1) # type: ignore
uuid = list(user.props.keys())[int(goods_name)]
goods_info = await GoodsInfo.get_or_none(uuid=uuid)
except IndexError:
return "仓库中道具不存在..."
else:
goods_info = await GoodsInfo.get_or_none(goods_name=goods_name)
if not goods_info:
@@ -647,9 +659,10 @@ class ShopManage:
shop = BuildImage(w, h, font_size=20, color="#f9f6f2")
await shop.paste(A, (20, 230))
await shop.paste(shop_logo, (450, 30))
tip = "注【通过 购买道具 序号 或者 商品名称 购买】"
await shop.text(
(
int((1000 - shop.getsize("注【通过 序号 或者 商品名称 购买】")[0]) / 2),
int((1000 - shop.getsize(tip)[0]) / 2),
170,
),
"注【通过 序号 或者 商品名称 购买】",