silly_girl 新增两个API (Sourcery refactored) (#77)

Co-authored-by: cdle <50124752+cdle@users.noreply.github.com>
Co-authored-by: Sourcery AI <>
This commit is contained in:
sourcery-ai[bot] 2022-09-18 22:46:44 +08:00 committed by GitHub
parent 2f0cf2a4f9
commit 88377ced67
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -4,9 +4,12 @@ from pagermaid.listener import listener
from pagermaid.enums import Message
from pagermaid.single_utils import sqlite
from pagermaid.utils import client, edit_delete
from pagermaid import bot
# from pagermaid import bot
from pyrogram.enums.chat_type import ChatType
from pagermaid.hook import Hook
from datetime import datetime, timedelta
from pagermaid.services import bot
from pyrogram.types import ChatPermissions
import json
@ -57,6 +60,26 @@ class SillyGirl:
replies = json.loads(req_data.text)
results = []
for reply in replies:
if reply["command"]:
try:
id = reply["id"]
cid = reply["chat_id"]
uid = reply["sender_id"]
if reply["command"] == "ban":
if id != 0 :
await bot.restrict_chat_member(cid, uid, ChatPermissions(),datetime.now() + timedelta(seconds=id))
else:
await bot.restrict_chat_member(cid, uid, ChatPermissions())
elif reply["command"] == "unban":
await bot.restrict_chat_member(cid, uid, ChatPermissions(),datetime.now() + timedelta(seconds=60))
elif reply["command"] == "kick":
if id != 0 :
await bot.ban_chat_member(cid,uid,datetime.now() + timedelta(seconds=60))
else:
await bot.ban_chat_member(cid,uid)
except Exception as e:
print(e,"----")
continue
if reply["delete"]:
try:
await bot.edit_message(reply["chat_id"], reply["id"], "打错字了,呱呱~")
@ -127,7 +150,12 @@ async def handle_receive(message: Message):
reply_to_sender_id = 0
chat_id = message.chat.id
sender_id = 0
user_name = ""
chat_name = message.chat.title or ""
if message.from_user:
user_name = message.from_user.first_name
if message.from_user.last_name:
user_name += f" {message.from_user.last_name}"
sender_id = message.from_user.id
if reply := message.reply_to_message:
reply_to = reply.id
@ -141,6 +169,8 @@ async def handle_receive(message: Message):
reply_to_sender_id = message.reply_to_message.from_user.id
if sillyGirl.init != True:
sillyGirl.init_connect_info("")
# if reply_to_sender_id==0 or sillyGirl.self_user_id == reply_to_sender_id:
# reply_to = 0
await sillyGirl.poll(
[
{
@ -153,6 +183,8 @@ async def handle_receive(message: Message):
'bot_id': sillyGirl.self_user_id,
'is_group': message.chat.type
in [ChatType.SUPERGROUP, ChatType.CHANNEL],
'user_name': user_name,
'chat_name': chat_name,
}
]
)