️ 优化金币红包

This commit is contained in:
HibiKier 2024-08-05 21:29:29 +08:00
parent 4cb350a003
commit dfbb7f347e
2 changed files with 10 additions and 9 deletions

View File

@ -1,7 +1,6 @@
import time import time
import uuid import uuid
from datetime import datetime, timedelta from datetime import datetime, timedelta
from typing import List
from apscheduler.jobstores.base import JobLookupError from apscheduler.jobstores.base import JobLookupError
from nonebot.adapters import Bot from nonebot.adapters import Bot
@ -44,7 +43,7 @@ __plugin_meta__ = PluginMetadata(
author="HibiKier", author="HibiKier",
version="0.1", version="0.1",
superuser_help=""" superuser_help="""
节日红包 [金额] [红包数] ?[指定主题文字] ? -g [群id] 节日红包 [金额] [红包数] ?[指定主题文字] ? -g [群id] [群id] ...
* 不同群组同一个节日红包用户只能开一次 * 不同群组同一个节日红包用户只能开一次
@ -116,7 +115,7 @@ _festive_matcher = on_alconna(
Alconna( Alconna(
"节日红包", "节日红包",
Args["amount", int]["num", int]["text?", str], Args["amount", int]["num", int]["text?", str],
Option("-g|--group", Args["group_list", str], help_text="指定群"), Option("-g|--group", Args["groups", str] / "\n", help_text="指定群"),
), ),
priority=1, priority=1,
block=True, block=True,
@ -275,25 +274,24 @@ async def _(
async def _( async def _(
bot: Bot, bot: Bot,
session: EventSession, session: EventSession,
arparma: Arparma,
amount: int, amount: int,
num: int, num: int,
text: Match[str], text: Match[str],
group_list: Match[str], groups: Match[str],
user_name: str = UserName(),
): ):
# TODO: 指定多个群 # TODO: 指定多个群
greetings = "恭喜发财 大吉大利" greetings = "恭喜发财 大吉大利"
if text.available: if text.available:
greetings = text.result greetings = text.result
gl = [] gl = []
if group_list.available: if groups.available:
gl = [group_list.result] gl = groups.result.strip().split()
else: else:
g_l, platform = await PlatformUtils.get_group_list(bot) g_l, platform = await PlatformUtils.get_group_list(bot)
gl = [g.channel_id or g.group_id for g in g_l] gl = [g.channel_id or g.group_id for g in g_l]
_uuid = str(uuid.uuid1()) _uuid = str(uuid.uuid1())
FestiveRedBagManage.add(_uuid) FestiveRedBagManage.add(_uuid)
_suc_cnt = 0
for g in gl: for g in gl:
if target := PlatformUtils.get_target(bot, group_id=g): if target := PlatformUtils.get_target(bot, group_id=g):
group_red_bag = RedBagManager.get_group_data(g) group_red_bag = RedBagManager.get_group_data(g)
@ -350,6 +348,9 @@ async def _(
Image(image_result.pic2bytes()), Image(image_result.pic2bytes()),
] ]
).send_to(target=target, bot=bot) ).send_to(target=target, bot=bot)
_suc_cnt += 1
logger.debug("节日红包图片信息发送成功...", "节日红包", group_id=g) logger.debug("节日红包图片信息发送成功...", "节日红包", group_id=g)
except ActionFailed: except ActionFailed:
logger.warning(f"节日红包图片信息发送失败...", "节日红包", group_id=g) logger.warning(f"节日红包图片信息发送失败...", "节日红包", group_id=g)
if gl:
await Text(f"节日红包发送成功,累计成功发送 {_suc_cnt} 个群组!").send()

View File

@ -35,7 +35,7 @@ __plugin_meta__ = PluginMetadata(
结算: 强行结束当前比赛 (仅当一方未开枪超过30秒时可使用) 结算: 强行结束当前比赛 (仅当一方未开枪超过30秒时可使用)
我的战绩: 你的战绩 我的战绩: 你的战绩
轮盘胜场排行/轮盘败场排行/轮盘欧洲人排行/轮盘慈善家排行/轮盘最高连胜排行/轮盘最高连败排行: 各种排行榜 轮盘胜场排行/轮盘败场排行/轮盘欧洲人排行/轮盘慈善家排行/轮盘最高连胜排行/轮盘最高连败排行: 各种排行榜
示例装弹 3 100 @sdd 示例装弹 100 3 @sdd
* 同一时间群内只能有一场对决 * * 同一时间群内只能有一场对决 *
""".strip(), """.strip(),
extra=PluginExtraData( extra=PluginExtraData(