vip 使用 conversation 重写

This commit is contained in:
xtaodada 2022-06-26 21:01:41 +08:00
parent 93533bd7d3
commit 711b3dcc11
Signed by: xtaodada
GPG Key ID: 4CBB3F4FA8C85659
2 changed files with 35 additions and 49 deletions

View File

@ -162,7 +162,7 @@
}, },
{ {
"name": "vip", "name": "vip",
"version": "0.72", "version": "0.721",
"section": "chat", "section": "chat",
"maintainer": "xtaodada", "maintainer": "xtaodada",
"size": "14.4 kb", "size": "14.4 kb",

View File

@ -1,7 +1,5 @@
from pyrogram import Client
from pyrogram.enums import ParseMode from pyrogram.enums import ParseMode
from asyncio import TimeoutError
from pagermaid.listener import listener from pagermaid.listener import listener
from pagermaid.utils import Message from pagermaid.utils import Message
@ -9,60 +7,52 @@ from pagermaid.utils import Message
@listener(command="duckduckgo", @listener(command="duckduckgo",
description="Duckduckgo 搜索", description="Duckduckgo 搜索",
parameters="<query>") parameters="<query>")
async def duckduckgo(client: Client, message: Message): async def duckduckgo(message: Message):
text = message.arguments text = message.arguments
if not text: if not text:
return await message.edit("请输入查询内容") return await message.edit("请输入查询内容")
try: async with message.bot.conversation("PagerMaid_Modify_bot") as conv:
answer: Message = await client.ask("PagerMaid_Modify_bot", f"/duckduckgo {text}") # noqa answer: Message = await conv.ask(f"/duckduckgo {text}")
await client.read_chat_history("PagerMaid_Modify_bot") await conv.mark_as_read()
except TimeoutError:
return await message.edit("获取时间超时,请稍后再试。")
await message.edit(answer.text.html, parse_mode=ParseMode.HTML) await message.edit(answer.text.html, parse_mode=ParseMode.HTML)
@listener(command="caiyun", @listener(command="caiyun",
description="彩云翻译", description="彩云翻译",
parameters="<query>") parameters="<query>")
async def caiyun_translate(client: Client, message: Message): async def caiyun_translate(message: Message):
text = message.arguments text = message.arguments
if not text: if not text:
return await message.edit("请输入查询内容") return await message.edit("请输入查询内容")
try: async with message.bot.conversation("PagerMaid_Modify_bot") as conv:
answer: Message = await client.ask("PagerMaid_Modify_bot", f"/translate {text}") # noqa answer: Message = await conv.ask(f"/translate {text}")
await client.read_chat_history("PagerMaid_Modify_bot") await conv.mark_as_read()
except TimeoutError:
return await message.edit("获取时间超时,请稍后再试。")
await message.edit(answer.text) await message.edit(answer.text)
@listener(command="weather", @listener(command="weather",
description="使用彩云天气 api 查询国内实时天气。", description="使用彩云天气 api 查询国内实时天气。",
parameters="<位置>") parameters="<位置>")
async def weather(client: Client, message: Message): async def weather(message: Message):
text = message.arguments text = message.arguments
if not text: if not text:
return await message.edit("请输入正确的地址") return await message.edit("请输入正确的地址")
try: async with message.bot.conversation("PagerMaid_Modify_bot") as conv:
answer: Message = await client.ask("PagerMaid_Modify_bot", f"/weather_api {text}") # noqa answer: Message = await conv.ask(f"/weather_api {text}")
await client.read_chat_history("PagerMaid_Modify_bot") await conv.mark_as_read()
except TimeoutError:
return await message.edit("获取时间超时,请稍后再试。")
await message.edit(answer.text) await message.edit(answer.text)
@listener(command="weather_pic", @listener(command="weather_pic",
description="使用彩云天气 api 查询国内实时天气,但是显示图片。", description="使用彩云天气 api 查询国内实时天气,但是显示图片。",
parameters="<位置>") parameters="<位置>")
async def weather_pic(client: Client, message: Message): async def weather_pic(message: Message):
text = message.arguments text = message.arguments
if not text: if not text:
return await message.edit("请输入正确的地址") return await message.edit("请输入正确的地址")
try: async with message.bot.conversation("PagerMaid_Modify_bot") as conv:
answer: Message = await client.ask("PagerMaid_Modify_bot", f"/weather {text}") # noqa answer: Message = await conv.ask(f"/weather {text}")
await client.read_chat_history("PagerMaid_Modify_bot") await conv.mark_as_read()
except TimeoutError:
return await message.edit("获取时间超时,请稍后再试。")
await answer.copy(message.chat.id, reply_to_message_id=message.reply_to_message_id) await answer.copy(message.chat.id, reply_to_message_id=message.reply_to_message_id)
await message.safe_delete() await message.safe_delete()
@ -70,28 +60,24 @@ async def weather_pic(client: Client, message: Message):
@listener(command="weather_he", @listener(command="weather_he",
description="使用和风天气 api 查询国内实时天气,但是显示图片。", description="使用和风天气 api 查询国内实时天气,但是显示图片。",
parameters="<位置>") parameters="<位置>")
async def weather_he(client: Client, message: Message): async def weather_he(message: Message):
text = message.arguments text = message.arguments
if not text: if not text:
return await message.edit("请输入正确的地址") return await message.edit("请输入正确的地址")
try: async with message.bot.conversation("PagerMaid_Modify_bot") as conv:
answer: Message = await client.ask("PagerMaid_Modify_bot", f"/weather_he {text}") # noqa answer: Message = await conv.ask(f"/weather_he {text}")
await client.read_chat_history("PagerMaid_Modify_bot") await conv.mark_as_read()
except TimeoutError:
return await message.edit("获取时间超时,请稍后再试。")
await answer.copy(message.chat.id, reply_to_message_id=message.reply_to_message_id) await answer.copy(message.chat.id, reply_to_message_id=message.reply_to_message_id)
await message.safe_delete() await message.safe_delete()
async def az_tts(client: Client, message: Message, mode: str): async def az_tts(message: Message, mode: str):
text = message.arguments text = message.arguments
if not text: if not text:
return await message.edit("请输入需要 tts 的内容") return await message.edit("请输入需要 tts 的内容")
try: async with message.bot.conversation("PagerMaid_Modify_bot") as conv:
answer: Message = await client.ask("PagerMaid_Modify_bot", f"/tts {text} {mode}") # noqa answer: Message = await conv.ask(f"/tts {text} {mode}")
await client.read_chat_history("PagerMaid_Modify_bot") await conv.mark_as_read()
except TimeoutError:
return await message.edit("获取时间超时,请稍后再试。")
await answer.copy(message.chat.id, reply_to_message_id=message.reply_to_message_id) await answer.copy(message.chat.id, reply_to_message_id=message.reply_to_message_id)
await message.safe_delete() await message.safe_delete()
@ -99,33 +85,33 @@ async def az_tts(client: Client, message: Message, mode: str):
@listener(command="tts_nan", @listener(command="tts_nan",
description="通过 Azure 文本到语音 基于字符串生成 简体男声 语音消息。", description="通过 Azure 文本到语音 基于字符串生成 简体男声 语音消息。",
parameters="<字符串>") parameters="<字符串>")
async def az_tts_nan(client: Client, message: Message): async def az_tts_nan(message: Message):
await az_tts(client, message, "") await az_tts(message, "")
@listener(command="tts_nv", @listener(command="tts_nv",
description="通过 Azure 文本到语音 基于字符串生成 简体女声 语音消息。", description="通过 Azure 文本到语音 基于字符串生成 简体女声 语音消息。",
parameters="<字符串>") parameters="<字符串>")
async def az_tts_nv(client: Client, message: Message): async def az_tts_nv(message: Message):
await az_tts(client, message, "nv") await az_tts(message, "nv")
@listener(command="tts_tw", @listener(command="tts_tw",
description="通过 Azure 文本到语音 基于字符串生成 繁体男声 语音消息。", description="通过 Azure 文本到语音 基于字符串生成 繁体男声 语音消息。",
parameters="<字符串>") parameters="<字符串>")
async def az_tts_tw(client: Client, message: Message): async def az_tts_tw(message: Message):
await az_tts(client, message, "tw") await az_tts(message, "tw")
@listener(command="tts_ne", @listener(command="tts_ne",
description="通过 Azure 文本到语音 基于字符串生成 简体新闻男声 语音消息。", description="通过 Azure 文本到语音 基于字符串生成 简体新闻男声 语音消息。",
parameters="<字符串>") parameters="<字符串>")
async def az_tts_ne(client: Client, message: Message): async def az_tts_ne(message: Message):
await az_tts(client, message, "ne") await az_tts(message, "ne")
@listener(command="tts_en", @listener(command="tts_en",
description="通过 Azure 文本到语音 基于字符串生成 英文男声 语音消息。", description="通过 Azure 文本到语音 基于字符串生成 英文男声 语音消息。",
parameters="<字符串>") parameters="<字符串>")
async def az_tts_en(client: Client, message: Message): async def az_tts_en(message: Message):
await az_tts(client, message, "en") await az_tts(message, "en")