PagerMaid_Plugins_Pyro/aff/main.py

52 lines
1.9 KiB
Python
Raw Normal View History

2022-08-21 07:19:56 +00:00
import contextlib
2023-01-10 06:51:38 +00:00
from typing import Tuple
2022-08-21 07:19:56 +00:00
from pagermaid.enums import Message
2023-01-10 06:51:38 +00:00
from pagermaid.services import sqlite
2022-08-21 07:19:56 +00:00
from pagermaid.listener import listener
2023-01-10 06:51:38 +00:00
def get_aff() -> Tuple[str, bool]:
return sqlite.get("aff.text", ""), sqlite.get("aff.web_page", False)
2022-08-21 07:19:56 +00:00
2023-01-10 06:51:38 +00:00
def set_aff(text: str, web_page: bool = False) -> None:
sqlite.update({"aff.text": text, "aff.web_page": web_page})
2022-08-21 07:19:56 +00:00
def del_aff() -> None:
2023-01-10 06:51:38 +00:00
text, web_page = get_aff()
if text:
2022-08-21 07:19:56 +00:00
del sqlite["aff.text"]
2023-01-10 06:51:38 +00:00
if web_page:
del sqlite["aff.web_page"]
2022-08-21 07:19:56 +00:00
2023-07-01 12:18:58 +00:00
@listener(
command="aff",
description="在别人要打算买机场的时候光速发出自己的aff信息(请尽量配合短链接)",
parameters="[save|remove] (可选,回复一条消息,用于保存|删除aff信息)",
)
2022-08-21 07:19:56 +00:00
async def aff(message: Message):
if not message.parameter:
2023-01-10 06:51:38 +00:00
msg, web_page = get_aff()
2022-08-21 07:19:56 +00:00
if not msg:
return await message.edit("出错了呜呜呜 ~ Aff消息不存在。\n(你有提前保存好嘛?)")
with contextlib.suppress(Exception):
2023-01-10 06:51:38 +00:00
await message.edit(msg, disable_web_page_preview=not web_page)
2022-08-21 07:19:56 +00:00
elif message.parameter[0] == "save":
if not message.reply_to_message:
return await message.edit("出错了呜呜呜 ~ 请回复一条消息以保存新的Aff信息。")
text = message.reply_to_message.text or message.reply_to_message.caption
2023-01-10 06:51:38 +00:00
web_page = message.reply_to_message.web_page or False
2022-08-21 07:19:56 +00:00
if not text:
return await message.edit("出错了呜呜呜 ~ 请回复一条消息以保存新的Aff信息。")
2023-01-10 06:51:38 +00:00
set_aff(text.html, web_page)
2022-08-21 07:19:56 +00:00
await message.edit("好耶 Aff信息保存成功。")
elif message.parameter[0] == "remove":
del_aff()
await message.edit("好耶 Aff信息删除成功。")
else:
await message.edit("出错了呜呜呜 ~ 无效的参数。")