插件上舰消息添加价格

This commit is contained in:
John Smith 2024-03-17 22:37:06 +08:00
parent da3e27c8cb
commit b2fc08def3
8 changed files with 18 additions and 17 deletions

View File

@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
__version__ = '0.0.1' # TODO 上舰消息加上price后再改成正式版
__version__ = '1.0.0'
from .handlers import *
from .client import *

View File

@ -321,6 +321,8 @@ class AddMemberMsg:
"""数量"""
unit: str = ''
"""单位(月)"""
total_coin: int = 0
"""总价付费瓜子数1000金瓜子 = 1元"""
uid: str = ''
"""用户Open ID或ID"""
medal_level: int = 0
@ -338,6 +340,7 @@ class AddMemberMsg:
privilege_type=data['privilegeType'],
num=data['num'],
unit=data['unit'],
total_coin=data['total_coin'],
uid=data['uid'],
medal_level=data['medalLevel'],
medal_name=data['medalName'],

View File

@ -78,7 +78,7 @@ class MsgHandler(blcsdk.BaseHandler):
if message.total_coin != 0:
content = (
f'[paid_gift] {message.author_name} 赠送了 {message.gift_name} x {message.num}'
f'总价 {message.total_coin / 1000}'
f'总价 {message.total_coin / 1000:.1f}'
)
else:
content = (
@ -101,7 +101,8 @@ class MsgHandler(blcsdk.BaseHandler):
guard_name = '总督'
else:
guard_name = '未知舰队等级'
room.log(f'[guard] {message.author_name} 购买了 {message.num}{message.unit} {guard_name}')
room.log(f'[guard] {message.author_name} 购买了 {message.num}{message.unit} {guard_name}'
f'总价 {message.total_coin / 1000:.1f}')
def _on_add_super_chat(
self, client: blcsdk.BlcPluginClient, message: sdk_models.AddSuperChatMsg, extra: sdk_models.ExtraData

View File

@ -88,19 +88,14 @@ class MsgHandler(blcsdk.BaseHandler):
return
room = _get_or_add_room(extra.room_key, extra.room_id)
# 消息里没有价格,这里按最低算
if message.privilege_type == sdk_models.GuardLevel.LV1:
guard_name = '舰长'
price = 138
elif message.privilege_type == sdk_models.GuardLevel.LV2:
guard_name = '提督'
price = 1998
elif message.privilege_type == sdk_models.GuardLevel.LV3:
guard_name = '总督'
price = 19998
else:
guard_name = '未知舰队等级'
price = 0
guard_name += f'{message.unit}'
room.add_gift(GiftRecord(
@ -108,7 +103,7 @@ class MsgHandler(blcsdk.BaseHandler):
author_name=message.author_name,
gift_name=guard_name,
num=message.num,
price=price,
price=message.total_coin / 1000,
))
def _on_add_super_chat(

View File

@ -56,12 +56,12 @@ class AppConfig:
self.max_tts_queue_size = 5
self.template_text = '{author_name}{content}'
self.template_text = '{author_name}{content}'
# self.template_free_gift = '{author_name} 赠送了{num}个{gift_name},总价{total_coin}银瓜子'
self.template_free_gift = '{author_name} 赠送了{num}{gift_name}'
self.template_paid_gift = '{author_name} 赠送了{num}{gift_name},总价{price:.1f}'
self.template_member = '{author_name} 购买了{num}{unit} {guard_name}'
self.template_super_chat = '{author_name} 发送了{price}元的醒目留言{content}'
self.template_member = '{author_name} 购买了{num}{unit} {guard_name},总价{price:.1f}'
self.template_super_chat = '{author_name} 发送了{price}元的醒目留言{content}'
def load(self, path):
try:

View File

@ -13,13 +13,13 @@ max_tts_queue_size = 5
# 消息模板,如果为空则不读
# 弹幕
template_text = {author_name} 说{content}
template_text = {author_name} 说{content}
# 免费礼物
# template_free_gift = {author_name} 赠送了{num}个{gift_name},总价{total_coin}银瓜子
template_free_gift = {author_name} 赠送了{num}个{gift_name}
# 付费礼物
template_paid_gift = {author_name} 赠送了{num}个{gift_name},总价{price:.1f}元
# 上舰
template_member = {author_name} 购买了{num}{unit} {guard_name}
template_member = {author_name} 购买了{num}{unit} {guard_name},总价{price:.1f}元
# 醒目留言
template_super_chat = {author_name} 发送了{price}元的醒目留言{content}
template_super_chat = {author_name} 发送了{price}元的醒目留言{content}

View File

@ -103,6 +103,8 @@ class MsgHandler(blcsdk.BaseHandler):
num=message.num,
unit=message.unit,
guard_name=guard_name,
price=message.total_coin / 1000,
total_coin=message.total_coin,
)
tts.say_text(text, tts.Priority.HIGH)

View File

@ -611,7 +611,7 @@ class LiveMsgHandler(blivedm.BaseHandler):
# 给插件用的字段
'num': message.num,
'unit': '', # 单位在USER_TOAST_MSG消息里不想改消息。现在没有别的单位web接口也很少有人用了先写死吧
# TODO price
'total_coin': message.price * message.num,
'uid': str(message.uid) if message.uid != 0 else message.username,
'medalLevel': 0,
'medalName': '',
@ -813,7 +813,7 @@ class LiveMsgHandler(blivedm.BaseHandler):
# 给插件用的字段
'num': message.guard_num,
'unit': message.guard_unit,
# TODO price
'total_coin': message.price * message.guard_num,
'uid': message.user_info.open_id,
'medalLevel': 0 if not message.fans_medal_wearing_status else message.fans_medal_level,
'medalName': '' if not message.fans_medal_wearing_status else message.fans_medal_name,