加入积分换灵石功能
This commit is contained in:
@@ -3,7 +3,7 @@
|
|||||||
[Xiuxian]
|
[Xiuxian]
|
||||||
enable = true
|
enable = true
|
||||||
# 指令集合(无需前缀),按核心/经济/信息/社交/门派分类
|
# 指令集合(无需前缀),按核心/经济/信息/社交/门派分类
|
||||||
command = ["修仙帮助", "注册修仙", "我的状态", "闭关", "出关", "聚灵", "排行榜", "修仙签到", "坊市", "购买", "乾坤袋", "突破", "强行突破", "劫掠", "赠与", "赠送", "创建门派", "加入门派", "退出门派"]
|
command = ["修仙帮助", "积分购石", "积分换灵石", "注册修仙", "我的状态", "闭关", "出关", "聚灵", "排行榜", "修仙签到", "坊市", "购买", "乾坤袋", "突破", "强行突破", "劫掠", "赠与", "赠送", "创建门派", "加入门派", "退出门派"]
|
||||||
# 用法提示:命令格式错误时的反馈文本
|
# 用法提示:命令格式错误时的反馈文本
|
||||||
command-format = """
|
command-format = """
|
||||||
📜修仙指令:
|
📜修仙指令:
|
||||||
@@ -23,6 +23,8 @@ enable = true
|
|||||||
赠与 - 赠送灵石
|
赠与 - 赠送灵石
|
||||||
赠送 - 赠送丹药物品
|
赠送 - 赠送丹药物品
|
||||||
|
|
||||||
|
积分购石 积分数
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
[Xiuxian.status]
|
[Xiuxian.status]
|
||||||
@@ -46,6 +48,7 @@ signin_seconds = 86400
|
|||||||
shop_seconds = 10
|
shop_seconds = 10
|
||||||
buy_seconds = 5
|
buy_seconds = 5
|
||||||
gift_seconds = 10
|
gift_seconds = 10
|
||||||
|
points_to_stone_seconds = 10
|
||||||
|
|
||||||
[Xiuxian.cultivation]
|
[Xiuxian.cultivation]
|
||||||
# 修为结算参数:基础速率(每小时),灵根乘数(名称:倍率)
|
# 修为结算参数:基础速率(每小时),灵根乘数(名称:倍率)
|
||||||
@@ -119,4 +122,6 @@ paths = [
|
|||||||
"炼气10层:hard:20000:0.1:筑基2层",
|
"炼气10层:hard:20000:0.1:筑基2层",
|
||||||
"筑基10层:pill:50000:0.2:金丹1层",
|
"筑基10层:pill:50000:0.2:金丹1层",
|
||||||
"筑基10层:hard:200000:0.05:金丹2层"
|
"筑基10层:hard:200000:0.05:金丹2层"
|
||||||
]
|
]
|
||||||
|
[Xiuxian.points_exchange]
|
||||||
|
point_to_stone_rate = 10
|
||||||
@@ -23,6 +23,7 @@ from utils.robot_cmd.robot_command import Feature, PermissionStatus, GroupBotMan
|
|||||||
from wechat_ipad import WechatAPIClient
|
from wechat_ipad import WechatAPIClient
|
||||||
from db.connection import DBConnectionManager
|
from db.connection import DBConnectionManager
|
||||||
from db.xiuxian_db import XiuxianDB
|
from db.xiuxian_db import XiuxianDB
|
||||||
|
from db.points_db import PointsDBOperator, PointSource
|
||||||
from datetime import timezone
|
from datetime import timezone
|
||||||
|
|
||||||
class XiuxianRedisDB:
|
class XiuxianRedisDB:
|
||||||
@@ -173,6 +174,7 @@ class XiuxianPlugin(MessagePluginInterface):
|
|||||||
self.feature = self.register_feature()
|
self.feature = self.register_feature()
|
||||||
self.redis_db: Optional[XiuxianRedisDB] = None
|
self.redis_db: Optional[XiuxianRedisDB] = None
|
||||||
self.xdb: Optional[XiuxianDB] = None
|
self.xdb: Optional[XiuxianDB] = None
|
||||||
|
self.points_db: Optional[PointsDBOperator] = None
|
||||||
|
|
||||||
def initialize(self, context: Dict[str, Any]) -> bool:
|
def initialize(self, context: Dict[str, Any]) -> bool:
|
||||||
"""初始化插件:加载配置,接入 DB 与 Redis,并注册功能权限。"""
|
"""初始化插件:加载配置,接入 DB 与 Redis,并注册功能权限。"""
|
||||||
@@ -186,6 +188,7 @@ class XiuxianPlugin(MessagePluginInterface):
|
|||||||
# 初始化持久化层(如连接池可用)
|
# 初始化持久化层(如连接池可用)
|
||||||
if self.db_manager.mysql_pool:
|
if self.db_manager.mysql_pool:
|
||||||
self.xdb = XiuxianDB(self.db_manager)
|
self.xdb = XiuxianDB(self.db_manager)
|
||||||
|
self.points_db = PointsDBOperator(self.db_manager)
|
||||||
try:
|
try:
|
||||||
self.xdb.init_schema()
|
self.xdb.init_schema()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@@ -221,6 +224,8 @@ class XiuxianPlugin(MessagePluginInterface):
|
|||||||
"创建门派": 86400,
|
"创建门派": 86400,
|
||||||
"加入门派": 604800,
|
"加入门派": 604800,
|
||||||
"退出门派": 604800,
|
"退出门派": 604800,
|
||||||
|
"积分购石": rate_cfg.get("points_to_stone_seconds", 10),
|
||||||
|
"积分换灵石": rate_cfg.get("points_to_stone_seconds", 10),
|
||||||
}
|
}
|
||||||
|
|
||||||
cult_cfg = cfg.get("cultivation", {})
|
cult_cfg = cfg.get("cultivation", {})
|
||||||
@@ -250,6 +255,9 @@ class XiuxianPlugin(MessagePluginInterface):
|
|||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
pts_cfg = cfg.get("points_exchange", {})
|
||||||
|
self.point_to_stone_rate = int(pts_cfg.get("point_to_stone_rate", 10))
|
||||||
|
|
||||||
bt_cfg = cfg.get("breakthrough", {})
|
bt_cfg = cfg.get("breakthrough", {})
|
||||||
self.bt_pill_threshold = int(bt_cfg.get("pill_threshold", 5000))
|
self.bt_pill_threshold = int(bt_cfg.get("pill_threshold", 5000))
|
||||||
self.bt_pill_item = bt_cfg.get("pill_item", "筑基丹")
|
self.bt_pill_item = bt_cfg.get("pill_item", "筑基丹")
|
||||||
@@ -346,8 +354,10 @@ class XiuxianPlugin(MessagePluginInterface):
|
|||||||
|
|
||||||
if cmd == "注册修仙":
|
if cmd == "注册修仙":
|
||||||
return await self._cmd_register(bot, sender, roomid, content)
|
return await self._cmd_register(bot, sender, roomid, content)
|
||||||
if cmd in ("修仙帮助"):
|
if cmd in ("修仙帮助", "帮助", "help", "修仙指令", "指令"):
|
||||||
return await self._cmd_help(bot, sender, roomid)
|
return await self._cmd_help(bot, sender, roomid)
|
||||||
|
if cmd in ("积分购石", "积分换灵石"):
|
||||||
|
return await self._cmd_points_to_stone(bot, sender, roomid, content)
|
||||||
if cmd == "我的状态":
|
if cmd == "我的状态":
|
||||||
return await self._cmd_status(bot, sender, roomid)
|
return await self._cmd_status(bot, sender, roomid)
|
||||||
if cmd == "闭关":
|
if cmd == "闭关":
|
||||||
@@ -455,11 +465,45 @@ class XiuxianPlugin(MessagePluginInterface):
|
|||||||
lines.append("劫掠 目标wxid")
|
lines.append("劫掠 目标wxid")
|
||||||
lines.append("创建门派 名称")
|
lines.append("创建门派 名称")
|
||||||
lines.append("加入门派 名称")
|
lines.append("加入门派 名称")
|
||||||
|
lines.append("积分购石 积分数")
|
||||||
msg = "\n".join(lines)
|
msg = "\n".join(lines)
|
||||||
await bot.send_text_message((roomid if roomid else sender), msg, sender)
|
await bot.send_text_message((roomid if roomid else sender), msg, sender)
|
||||||
self._rate_set(sender, "帮助")
|
self._rate_set(sender, "帮助")
|
||||||
return True, "帮助"
|
return True, "帮助"
|
||||||
|
|
||||||
|
async def _cmd_points_to_stone(self, bot: WechatAPIClient, sender: str, roomid: str, content: str) -> Tuple[bool, str]:
|
||||||
|
if not self.points_db:
|
||||||
|
await bot.send_text_message(roomid or sender, "系统未初始化积分模块", sender)
|
||||||
|
return False, "积分未初始化"
|
||||||
|
player = self._get_player(sender)
|
||||||
|
if not player:
|
||||||
|
await bot.send_text_message(roomid or sender, "未注册,请先发送:注册修仙 道号", sender)
|
||||||
|
return False, "未注册"
|
||||||
|
try:
|
||||||
|
pts = int(content.strip())
|
||||||
|
except Exception:
|
||||||
|
await bot.send_text_message(roomid or sender, "命令格式:积分购石 积分数", sender)
|
||||||
|
return False, "命令格式错误"
|
||||||
|
if pts <= 0:
|
||||||
|
await bot.send_text_message(roomid or sender, "积分数需为正整数", sender)
|
||||||
|
return False, "非法数量"
|
||||||
|
group_id = roomid or ""
|
||||||
|
ok, res = self.points_db.deduct_points(sender, group_id, pts, PointSource.PLUGIN, "修仙购买灵石")
|
||||||
|
if not ok:
|
||||||
|
cur = res.get("current_points", 0)
|
||||||
|
await bot.send_text_message(roomid or sender, f"积分不足,当前积分:{cur}", sender)
|
||||||
|
return False, "积分不足"
|
||||||
|
rate = int(self.point_to_stone_rate)
|
||||||
|
if pts < rate:
|
||||||
|
await bot.send_text_message(roomid or sender, f"积分不足以兑换1灵石,至少需要{rate}积分", sender)
|
||||||
|
return False, "积分不足"
|
||||||
|
stones_gain = pts // rate
|
||||||
|
player["spirit_stone"] = int(player.get("spirit_stone", 0)) + stones_gain
|
||||||
|
self._save_player(player)
|
||||||
|
self._rate_set(sender, "积分购石")
|
||||||
|
await bot.send_text_message(roomid or sender, f"✅ 兑换成功,消耗积分{pts},获得灵石{stones_gain}({rate}积分=1灵石)", sender)
|
||||||
|
return True, "积分购石"
|
||||||
|
|
||||||
async def _cmd_status(self, bot: WechatAPIClient, sender: str, roomid: str) -> Tuple[bool, str]:
|
async def _cmd_status(self, bot: WechatAPIClient, sender: str, roomid: str) -> Tuple[bool, str]:
|
||||||
player = self.redis_db.get_player(sender)
|
player = self.redis_db.get_player(sender)
|
||||||
if not player:
|
if not player:
|
||||||
|
|||||||
Reference in New Issue
Block a user