mirror of
https://github.com/TeamPGM/PagerMaid_Plugins_Pyro.git
synced 2024-11-25 20:56:30 +00:00
silly_girl 逻辑优化 (#74)
Co-authored-by: cdle <50124752+cdle@users.noreply.github.com> Co-authored-by: Sourcery AI <>
This commit is contained in:
parent
8df55d835a
commit
309ef7063f
@ -1,3 +1,4 @@
|
|||||||
|
|
||||||
from asyncio import sleep
|
from asyncio import sleep
|
||||||
from pagermaid.listener import listener
|
from pagermaid.listener import listener
|
||||||
from pagermaid.enums import Message
|
from pagermaid.enums import Message
|
||||||
@ -7,56 +8,53 @@ from pagermaid import bot
|
|||||||
from pyrogram.enums.chat_type import ChatType
|
from pyrogram.enums.chat_type import ChatType
|
||||||
from pagermaid.hook import Hook
|
from pagermaid.hook import Hook
|
||||||
|
|
||||||
|
import json
|
||||||
|
|
||||||
class SillyGirl:
|
class SillyGirl:
|
||||||
address = ""
|
address = ""
|
||||||
token = ""
|
token = ""
|
||||||
self_user_id = ""
|
self_user_id = ""
|
||||||
init = False
|
init = False
|
||||||
|
working = False
|
||||||
|
|
||||||
def init_connect_info(self, address):
|
def init_connect_info(self, address):
|
||||||
|
sillyGirl.self_user_id = bot.me.id
|
||||||
self.init = True
|
self.init = True
|
||||||
self.self_user_id = bot.me.id
|
|
||||||
if address:
|
if address:
|
||||||
sqlite["silly_girl_address"] = address
|
sqlite["silly_girl_address"] = address
|
||||||
else:
|
else:
|
||||||
address = sqlite.get("silly_girl_address", "")
|
address = sqlite.get("silly_girl_address")
|
||||||
try:
|
if '@' in address:
|
||||||
if '@' in address:
|
|
||||||
s1 = address.split("//", 1)
|
s1 = address.split("//", 1)
|
||||||
s2 = s1[1].split("@", 1)
|
s2 = s1[1].split("@", 1)
|
||||||
sillyGirl.token = s2[0]
|
sillyGirl.token = s2[0]
|
||||||
self.address = f"{s1[0]}//{s2[1]}"
|
address = f"{s1[0]}//{s2[1]}"
|
||||||
except:
|
sillyGirl.address = address
|
||||||
self.address = ""
|
|
||||||
|
|
||||||
async def polls(self):
|
async def polls(self):
|
||||||
while True:
|
while True:
|
||||||
if self.address:
|
await self.poll([])
|
||||||
await self.poll([])
|
|
||||||
else:
|
|
||||||
return
|
|
||||||
|
|
||||||
async def poll(self, data):
|
async def poll(self, data):
|
||||||
try:
|
try:
|
||||||
if not self.address:
|
|
||||||
return
|
|
||||||
init = ''
|
init = ''
|
||||||
if not self.init:
|
if sillyGirl.init == False:
|
||||||
init = "&init=true"
|
init = "&init=true"
|
||||||
self.init = True
|
sillyGirl.init = True
|
||||||
req_data = await client.post(
|
req_data = await client.post(
|
||||||
f"{self.address}/pgm?token={self.token}{init}", json=data
|
f"{self.address}/pgm?token={self.token}{init}", json=data
|
||||||
)
|
)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
print(e)
|
||||||
|
print(e,"???====")
|
||||||
await sleep(0.1)
|
await sleep(0.1)
|
||||||
return
|
return
|
||||||
if req_data.status_code != 200:
|
if req_data.status_code != 200:
|
||||||
await sleep(0.1)
|
await sleep(0.1)
|
||||||
return
|
return
|
||||||
try:
|
try:
|
||||||
replies = req_data.json()
|
replies = json.loads(req_data.text)
|
||||||
results = []
|
results = []
|
||||||
for reply in replies:
|
for reply in replies:
|
||||||
if reply["delete"]:
|
if reply["delete"]:
|
||||||
@ -82,6 +80,13 @@ class SillyGirl:
|
|||||||
caption=reply["text"],
|
caption=reply["text"],
|
||||||
reply_to_message_id=reply["reply_to"],
|
reply_to_message_id=reply["reply_to"],
|
||||||
)
|
)
|
||||||
|
elif reply["videos"] and len(reply["videos"]) != 0:
|
||||||
|
message = await bot.send_video(
|
||||||
|
reply["chat_id"],
|
||||||
|
reply["videos"][0],
|
||||||
|
caption=reply["text"],
|
||||||
|
reply_to_message_id=reply["reply_to"],
|
||||||
|
)
|
||||||
elif reply["text"] != '':
|
elif reply["text"] != '':
|
||||||
message = await bot.send_message(reply["chat_id"], reply["text"], reply_to_message_id=reply["reply_to"])
|
message = await bot.send_message(reply["chat_id"], reply["text"], reply_to_message_id=reply["reply_to"])
|
||||||
if message:
|
if message:
|
||||||
@ -90,56 +95,71 @@ class SillyGirl:
|
|||||||
'uuid': reply["uuid"],
|
'uuid': reply["uuid"],
|
||||||
})
|
})
|
||||||
if len(results):
|
if len(results):
|
||||||
await self.poll(results)
|
await sillyGirl.poll(results)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
print(e,"???")
|
||||||
await sleep(0.1)
|
await sleep(0.1)
|
||||||
|
return
|
||||||
|
|
||||||
sillyGirl = SillyGirl()
|
sillyGirl = SillyGirl()
|
||||||
|
|
||||||
|
|
||||||
@Hook.on_startup()
|
@Hook.on_startup()
|
||||||
async def connect_sillyGirl():
|
async def connect_sillyGirl():
|
||||||
sillyGirl.init_connect_info("")
|
sillyGirl.init_connect_info("")
|
||||||
bot.loop.create_task(sillyGirl.polls())
|
bot.loop.create_task(sillyGirl.polls())
|
||||||
|
bot.loop.create_task(sillyGirl.polls())
|
||||||
|
|
||||||
|
|
||||||
@listener(command="sillyGirl", description="连接到傻妞服务器", parameters="<auth>")
|
|
||||||
async def sillyGirl_connect(message: Message):
|
@listener(is_plugin=True,outgoing=True, ignore_edited=True, command="sillyGirl",description="连接到傻妞服务器", parameters="<auth>")
|
||||||
|
async def Connect(message: Message):
|
||||||
try:
|
try:
|
||||||
await edit_delete(message, "连接中...")
|
await edit_delete(message,"连接中,建议重启...")
|
||||||
sillyGirl.init_connect_info(message.arguments)
|
sillyGirl.init_connect_info(message.arguments)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
print(e,"+++")
|
||||||
print(e)
|
print(e)
|
||||||
|
|
||||||
|
@listener(outgoing=True,ignore_edited=True, incoming=True)
|
||||||
@listener(outgoing=True, ignore_edited=True, incoming=True)
|
|
||||||
async def handle_receive(message: Message):
|
async def handle_receive(message: Message):
|
||||||
try:
|
try:
|
||||||
reply_to = message.id
|
reply_to = message.id
|
||||||
reply = message.reply_to_message
|
|
||||||
reply_to_sender_id = 0
|
reply_to_sender_id = 0
|
||||||
|
chat_id = message.chat.id
|
||||||
sender_id = 0
|
sender_id = 0
|
||||||
if message.from_user:
|
if message.from_user:
|
||||||
sender_id = message.from_user.id
|
sender_id = message.from_user.id
|
||||||
if reply:
|
if reply := message.reply_to_message:
|
||||||
reply_to = reply.id
|
reply_to = reply.id
|
||||||
reply_to_sender_id = reply.from_user.id
|
if reply.from_user:
|
||||||
if not sillyGirl.init:
|
reply_to_sender_id = reply.from_user.id
|
||||||
|
if message.reply_to_message_id:
|
||||||
|
reply_to = message.reply_to_message_id
|
||||||
|
if message.reply_to_message:
|
||||||
|
reply_to = message.reply_to_message.id
|
||||||
|
if message.reply_to_message.from_user:
|
||||||
|
reply_to_sender_id = message.reply_to_message.from_user.id
|
||||||
|
if sillyGirl.init != True:
|
||||||
sillyGirl.init_connect_info("")
|
sillyGirl.init_connect_info("")
|
||||||
if sillyGirl.self_user_id == sender_id:
|
|
||||||
reply_to = 0
|
|
||||||
await sillyGirl.poll(
|
await sillyGirl.poll(
|
||||||
[{
|
[
|
||||||
'id': message.id,
|
{
|
||||||
'chat_id': message.chat.id,
|
'id': message.id,
|
||||||
'text': message.text,
|
'chat_id': chat_id,
|
||||||
'sender_id': sender_id,
|
'text': message.text,
|
||||||
'reply_to': reply_to,
|
'sender_id': sender_id,
|
||||||
'reply_to_sender_id': reply_to_sender_id,
|
'reply_to': reply_to,
|
||||||
'bot_id': sillyGirl.self_user_id,
|
'reply_to_sender_id': reply_to_sender_id,
|
||||||
'is_group': message.chat.type != ChatType.PRIVATE,
|
'bot_id': sillyGirl.self_user_id,
|
||||||
}])
|
'is_group': message.chat.type
|
||||||
|
in [ChatType.SUPERGROUP, ChatType.CHANNEL],
|
||||||
|
}
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
print(e)
|
||||||
|
print(e,"---")
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user