2022-09-05 06:09:29 +00:00
|
|
|
from asyncio import sleep
|
|
|
|
from pagermaid.listener import listener
|
|
|
|
from pagermaid.enums import Message
|
|
|
|
from pagermaid.single_utils import sqlite
|
|
|
|
from pagermaid.utils import client, edit_delete
|
2023-07-01 12:18:58 +00:00
|
|
|
|
2022-09-18 14:46:44 +00:00
|
|
|
# from pagermaid import bot
|
2022-09-05 06:09:29 +00:00
|
|
|
from pyrogram.enums.chat_type import ChatType
|
|
|
|
from pagermaid.hook import Hook
|
2022-09-18 14:46:44 +00:00
|
|
|
from datetime import datetime, timedelta
|
|
|
|
from pagermaid.services import bot
|
|
|
|
from pyrogram.types import ChatPermissions
|
2022-09-05 06:09:29 +00:00
|
|
|
|
2022-09-14 13:39:43 +00:00
|
|
|
import json
|
2022-09-05 06:09:29 +00:00
|
|
|
|
2023-07-01 12:18:58 +00:00
|
|
|
|
2022-09-05 06:09:29 +00:00
|
|
|
class SillyGirl:
|
|
|
|
address = ""
|
|
|
|
token = ""
|
|
|
|
self_user_id = ""
|
|
|
|
init = False
|
2022-09-14 13:39:43 +00:00
|
|
|
working = False
|
2022-09-05 06:09:29 +00:00
|
|
|
|
|
|
|
def init_connect_info(self, address):
|
2022-09-14 13:39:43 +00:00
|
|
|
sillyGirl.self_user_id = bot.me.id
|
2022-09-05 06:09:29 +00:00
|
|
|
self.init = True
|
|
|
|
if address:
|
|
|
|
sqlite["silly_girl_address"] = address
|
|
|
|
else:
|
2022-09-14 13:39:43 +00:00
|
|
|
address = sqlite.get("silly_girl_address")
|
2023-07-01 12:18:58 +00:00
|
|
|
if "@" in address:
|
2022-09-05 06:09:29 +00:00
|
|
|
s1 = address.split("//", 1)
|
|
|
|
s2 = s1[1].split("@", 1)
|
|
|
|
sillyGirl.token = s2[0]
|
2022-09-14 13:39:43 +00:00
|
|
|
address = f"{s1[0]}//{s2[1]}"
|
|
|
|
sillyGirl.address = address
|
2022-09-05 06:09:29 +00:00
|
|
|
|
|
|
|
async def polls(self):
|
|
|
|
while True:
|
2022-09-14 13:39:43 +00:00
|
|
|
await self.poll([])
|
2022-09-05 06:09:29 +00:00
|
|
|
|
|
|
|
async def poll(self, data):
|
|
|
|
try:
|
2023-07-01 12:18:58 +00:00
|
|
|
init = ""
|
2022-09-14 13:39:43 +00:00
|
|
|
if sillyGirl.init == False:
|
2022-09-05 06:09:29 +00:00
|
|
|
init = "&init=true"
|
2022-09-14 13:39:43 +00:00
|
|
|
sillyGirl.init = True
|
2022-09-05 06:09:29 +00:00
|
|
|
req_data = await client.post(
|
|
|
|
f"{self.address}/pgm?token={self.token}{init}", json=data
|
|
|
|
)
|
2022-09-14 13:39:43 +00:00
|
|
|
|
2022-09-05 06:09:29 +00:00
|
|
|
except Exception as e:
|
|
|
|
print(e)
|
2023-07-01 12:18:58 +00:00
|
|
|
print(e, "???====")
|
2022-09-05 06:09:29 +00:00
|
|
|
await sleep(0.1)
|
|
|
|
return
|
|
|
|
if req_data.status_code != 200:
|
|
|
|
await sleep(0.1)
|
|
|
|
return
|
|
|
|
try:
|
2022-09-14 13:39:43 +00:00
|
|
|
replies = json.loads(req_data.text)
|
2022-09-05 06:09:29 +00:00
|
|
|
results = []
|
|
|
|
for reply in replies:
|
2022-09-18 14:46:44 +00:00
|
|
|
if reply["command"]:
|
|
|
|
try:
|
|
|
|
id = reply["id"]
|
|
|
|
cid = reply["chat_id"]
|
|
|
|
uid = reply["sender_id"]
|
|
|
|
if reply["command"] == "ban":
|
2023-07-01 12:18:58 +00:00
|
|
|
if id != 0:
|
|
|
|
await bot.restrict_chat_member(
|
|
|
|
cid,
|
|
|
|
uid,
|
|
|
|
ChatPermissions(),
|
|
|
|
datetime.now() + timedelta(seconds=id),
|
|
|
|
)
|
2022-09-18 14:46:44 +00:00
|
|
|
else:
|
2023-07-01 12:18:58 +00:00
|
|
|
await bot.restrict_chat_member(
|
|
|
|
cid, uid, ChatPermissions()
|
|
|
|
)
|
2022-09-18 14:46:44 +00:00
|
|
|
elif reply["command"] == "unban":
|
2023-07-01 12:18:58 +00:00
|
|
|
await bot.restrict_chat_member(
|
|
|
|
cid,
|
|
|
|
uid,
|
|
|
|
ChatPermissions(),
|
|
|
|
datetime.now() + timedelta(seconds=60),
|
|
|
|
)
|
2022-09-18 14:46:44 +00:00
|
|
|
elif reply["command"] == "kick":
|
2023-07-01 12:18:58 +00:00
|
|
|
if id != 0:
|
|
|
|
await bot.ban_chat_member(
|
|
|
|
cid, uid, datetime.now() + timedelta(seconds=60)
|
|
|
|
)
|
2022-09-18 14:46:44 +00:00
|
|
|
else:
|
2023-07-01 12:18:58 +00:00
|
|
|
await bot.ban_chat_member(cid, uid)
|
2022-09-18 14:46:44 +00:00
|
|
|
except Exception as e:
|
2023-07-01 12:18:58 +00:00
|
|
|
print(e, "----")
|
2022-09-18 14:46:44 +00:00
|
|
|
continue
|
2022-09-05 06:09:29 +00:00
|
|
|
if reply["delete"]:
|
|
|
|
try:
|
2023-07-01 12:18:58 +00:00
|
|
|
await bot.edit_message(
|
|
|
|
reply["chat_id"], reply["id"], "打错字了,呱呱~"
|
|
|
|
)
|
2022-09-05 06:09:29 +00:00
|
|
|
except Exception as e:
|
|
|
|
pass
|
|
|
|
try:
|
|
|
|
await bot.delete_messages(reply["chat_id"], [reply["id"]])
|
|
|
|
except Exception as e:
|
|
|
|
pass
|
|
|
|
if reply["id"] != 0:
|
|
|
|
try:
|
2023-07-01 12:18:58 +00:00
|
|
|
await bot.edit_message(
|
|
|
|
reply["chat_id"], reply["id"], reply["text"]
|
|
|
|
)
|
2022-09-05 06:09:29 +00:00
|
|
|
continue
|
|
|
|
except Exception as e:
|
|
|
|
continue
|
|
|
|
message: Message
|
|
|
|
if reply["images"] and len(reply["images"]) != 0:
|
|
|
|
message = await bot.send_photo(
|
|
|
|
reply["chat_id"],
|
|
|
|
reply["images"][0],
|
|
|
|
caption=reply["text"],
|
|
|
|
reply_to_message_id=reply["reply_to"],
|
|
|
|
)
|
2022-09-14 13:39:43 +00:00
|
|
|
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"],
|
|
|
|
)
|
2023-07-01 12:18:58 +00:00
|
|
|
elif reply["text"] != "":
|
|
|
|
message = await bot.send_message(
|
|
|
|
reply["chat_id"],
|
|
|
|
reply["text"],
|
|
|
|
reply_to_message_id=reply["reply_to"],
|
|
|
|
)
|
2022-09-05 06:09:29 +00:00
|
|
|
if message:
|
2023-07-01 12:18:58 +00:00
|
|
|
results.append(
|
|
|
|
{
|
|
|
|
"id": message.id,
|
|
|
|
"uuid": reply["uuid"],
|
|
|
|
}
|
|
|
|
)
|
2022-09-05 06:09:29 +00:00
|
|
|
if len(results):
|
2022-09-14 13:39:43 +00:00
|
|
|
await sillyGirl.poll(results)
|
2022-09-05 06:09:29 +00:00
|
|
|
except Exception as e:
|
2023-07-01 12:18:58 +00:00
|
|
|
print(e, "???")
|
2022-09-05 06:09:29 +00:00
|
|
|
await sleep(0.1)
|
2022-09-14 13:39:43 +00:00
|
|
|
return
|
2022-09-05 06:09:29 +00:00
|
|
|
|
2023-07-01 12:18:58 +00:00
|
|
|
|
2022-09-05 06:09:29 +00:00
|
|
|
sillyGirl = SillyGirl()
|
|
|
|
|
2023-07-01 12:18:58 +00:00
|
|
|
|
2022-09-05 06:09:29 +00:00
|
|
|
@Hook.on_startup()
|
|
|
|
async def connect_sillyGirl():
|
|
|
|
sillyGirl.init_connect_info("")
|
|
|
|
bot.loop.create_task(sillyGirl.polls())
|
2022-09-14 13:39:43 +00:00
|
|
|
bot.loop.create_task(sillyGirl.polls())
|
2022-09-05 06:09:29 +00:00
|
|
|
|
|
|
|
|
2023-07-01 12:18:58 +00:00
|
|
|
@listener(
|
|
|
|
is_plugin=True,
|
|
|
|
outgoing=True,
|
|
|
|
ignore_edited=True,
|
|
|
|
command="sillyGirl",
|
|
|
|
description="连接到傻妞服务器",
|
|
|
|
parameters="[auth]",
|
|
|
|
)
|
2022-09-14 13:39:43 +00:00
|
|
|
async def Connect(message: Message):
|
2023-07-01 12:18:58 +00:00
|
|
|
try:
|
|
|
|
await edit_delete(message, "连接中,建议重启...")
|
2022-09-05 06:09:29 +00:00
|
|
|
sillyGirl.init_connect_info(message.arguments)
|
|
|
|
except Exception as e:
|
2023-07-01 12:18:58 +00:00
|
|
|
print(e, "+++")
|
2022-09-05 06:09:29 +00:00
|
|
|
print(e)
|
|
|
|
|
2023-07-01 12:18:58 +00:00
|
|
|
|
|
|
|
@listener(outgoing=True, ignore_edited=True, incoming=True)
|
2022-09-05 06:09:29 +00:00
|
|
|
async def handle_receive(message: Message):
|
2023-07-01 12:18:58 +00:00
|
|
|
try:
|
2022-09-05 06:09:29 +00:00
|
|
|
reply_to = message.id
|
|
|
|
reply_to_sender_id = 0
|
2022-09-14 13:39:43 +00:00
|
|
|
chat_id = message.chat.id
|
2022-09-05 06:09:29 +00:00
|
|
|
sender_id = 0
|
2022-09-18 14:46:44 +00:00
|
|
|
user_name = ""
|
|
|
|
chat_name = message.chat.title or ""
|
2022-09-05 06:09:29 +00:00
|
|
|
if message.from_user:
|
2022-09-18 14:46:44 +00:00
|
|
|
user_name = message.from_user.first_name
|
|
|
|
if message.from_user.last_name:
|
|
|
|
user_name += f" {message.from_user.last_name}"
|
2022-09-05 06:09:29 +00:00
|
|
|
sender_id = message.from_user.id
|
2022-09-14 13:39:43 +00:00
|
|
|
if reply := message.reply_to_message:
|
2022-09-05 06:09:29 +00:00
|
|
|
reply_to = reply.id
|
2022-09-14 13:39:43 +00:00
|
|
|
if reply.from_user:
|
|
|
|
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:
|
2022-09-05 06:09:29 +00:00
|
|
|
sillyGirl.init_connect_info("")
|
2022-09-18 14:46:44 +00:00
|
|
|
# if reply_to_sender_id==0 or sillyGirl.self_user_id == reply_to_sender_id:
|
|
|
|
# reply_to = 0
|
2022-09-05 06:09:29 +00:00
|
|
|
await sillyGirl.poll(
|
2022-09-14 13:39:43 +00:00
|
|
|
[
|
|
|
|
{
|
2023-07-01 12:18:58 +00:00
|
|
|
"id": message.id,
|
|
|
|
"chat_id": chat_id,
|
|
|
|
"text": message.text,
|
|
|
|
"sender_id": sender_id,
|
|
|
|
"reply_to": reply_to,
|
|
|
|
"reply_to_sender_id": reply_to_sender_id,
|
|
|
|
"bot_id": sillyGirl.self_user_id,
|
|
|
|
"is_group": message.chat.type
|
2022-09-14 13:39:43 +00:00
|
|
|
in [ChatType.SUPERGROUP, ChatType.CHANNEL],
|
2023-07-01 12:18:58 +00:00
|
|
|
"user_name": user_name,
|
|
|
|
"chat_name": chat_name,
|
2022-09-14 13:39:43 +00:00
|
|
|
}
|
|
|
|
]
|
|
|
|
)
|
|
|
|
|
2022-09-05 06:09:29 +00:00
|
|
|
except Exception as e:
|
|
|
|
print(e)
|
2023-07-01 12:18:58 +00:00
|
|
|
print(e, "---")
|
2022-09-14 13:39:43 +00:00
|
|
|
return
|