Files
NewWPSBot/Plugins/WPSRedPacketClaim.py

56 lines
1.7 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from __future__ import annotations
from typing import Optional, Sequence
from Plugins.WPSAPI import GuideEntry
from .WPSRedPacketBase import WPSRedPacketBase
class WPSRedPacketClaim(WPSRedPacketBase):
"""抢红包入口"""
def get_guide_subtitle(self) -> str:
return "通过红包ID领取积分奖励"
def collect_command_entries(self):
return (
GuideEntry(
title="抢红包",
identifier="抢红包 <红包ID> [口令]",
description="输入红包ID后领取剩余份额口令红包需附带口令。",
),
)
def wake_up(self) -> None:
self.register_plugin("抢红包")
async def callback(self, message: str, chat_id: int, user_id: int) -> Optional[str]:
payload = self.parse_message_after_at(message).strip()
tokens = [token.strip() for token in payload.split() if token.strip()]
if not tokens:
return await self.send_markdown_message(
self.format_error("指令格式:`抢红包 <红包ID> [口令]`"),
chat_id,
user_id,
)
packet_id = tokens[0]
extra_tokens: Sequence[str] = tokens[1:]
username = self.config_api().get_user_name(user_id)
service = self.red_packet_service()
success, message_text, _ = service.claim_packet(
chat_id,
packet_id,
user_id,
username,
extra_tokens,
)
if success:
return await self.send_markdown_message(message_text, chat_id, user_id)
return await self.send_markdown_message(message_text, chat_id, user_id)
__all__ = ["WPSRedPacketClaim"]