From ceb184bddcedde432df2e5e9a1ac3ab704c6adf6 Mon Sep 17 00:00:00 2001 From: cdle <50124752+cdle@users.noreply.github.com> Date: Sat, 27 Aug 2022 21:24:09 +0800 Subject: [PATCH] =?UTF-8?q?silly=5Fgirl=20=E4=BF=AE=E5=A4=8D=E5=AE=89?= =?UTF-8?q?=E8=A3=85=E5=90=8E=E9=87=8D=E5=90=AF=E5=81=87=E6=AD=BB=20(#16)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 同时增加了token验证 Co-authored-by: omg-xtao <100690902+omg-xtao@users.noreply.github.com> --- list.json | 2 +- silly_girl.py | 58 ++++++++++++++++++++++++--------------------------- 2 files changed, 28 insertions(+), 32 deletions(-) diff --git a/list.json b/list.json index c3e294e..046bad5 100644 --- a/list.json +++ b/list.json @@ -852,7 +852,7 @@ }, { "name": "silly_girl", - "version": "1.031", + "version": "1.04", "section": "chat", "maintainer": "cdle", "size": "3 kb", diff --git a/silly_girl.py b/silly_girl.py index ad2ed88..9f508b1 100644 --- a/silly_girl.py +++ b/silly_girl.py @@ -15,10 +15,10 @@ persistent_vars.update( 'times': 0, 'started': False, 'self_user_id': 0, - 'secret': '', + 'token': '', 'url': '', 'init': False, - 'whiltelist': '', + 'restart': False, } } ) @@ -43,7 +43,7 @@ async def sillyGirl(context): if '@' in text: s1 = text.split("//", 1) s2 = s1[1].split("@", 1) - persistent_vars["sillyGirl"]['secret'] = s2[0] + persistent_vars["sillyGirl"]['token'] = s2[0] text = s1[0]+"//"+s2[1] os.close(fd) persistent_vars["sillyGirl"]['url'] = text @@ -51,43 +51,42 @@ async def sillyGirl(context): persistent_vars["sillyGirl"]['self_user_id'] = myself.id if persistent_vars["sillyGirl"]['started'] == False: persistent_vars["sillyGirl"]['started'] = True - while(True): + while(persistent_vars["sillyGirl"]['restart']==False): await poll([]) - @listener(is_plugin=True, outgoing=True, incoming=True) -async def xxx(context): +async def handle_receive(context): if persistent_vars["sillyGirl"]['started'] == False: - return + await sillyGirl(context) reply_to = 0 reply_to = context.id reply = await context.get_reply_message() reply_to_sender_id = 0 - if context.sender_id == persistent_vars["sillyGirl"]['self_user_id'] or str(context.sender_id) in persistent_vars["sillyGirl"]['whiltelist'] or str(context.chat_id) in persistent_vars["sillyGirl"]['whiltelist']: - if reply: - reply_to = reply.id - reply_to_sender_id = reply.sender_id - elif persistent_vars["sillyGirl"]['self_user_id'] == context.sender_id or context.is_private: - reply_to = 0 - await poll( - [{ - 'id': context.id, - 'chat_id': context.chat_id, - 'text': context.text, - 'sender_id': context.sender_id, - 'reply_to': reply_to, - 'reply_to_sender_id': reply_to_sender_id, - 'bot_id': persistent_vars["sillyGirl"]['self_user_id'], - 'is_group': context.is_private == False, - }]) - + if context.text == "-restart" and persistent_vars["sillyGirl"]['self_user_id'] == context.sender_id: + persistent_vars["sillyGirl"]['restart'] = True + if reply: + reply_to = reply.id + reply_to_sender_id = reply.sender_id + elif persistent_vars["sillyGirl"]['self_user_id'] == context.sender_id or context.is_private: + reply_to = 0 + await poll( + [{ + 'id': context.id, + 'chat_id': context.chat_id, + 'text': context.text, + 'sender_id': context.sender_id, + 'reply_to': reply_to, + 'reply_to_sender_id': reply_to_sender_id, + 'bot_id': persistent_vars["sillyGirl"]['self_user_id'], + 'is_group': context.is_private == False, + }]) async def poll(data): try: init = "" if persistent_vars["sillyGirl"]['init'] == False: - init = "?init=true" - req_data = await client.post(persistent_vars["sillyGirl"]['url']+"/pgm"+init, json=data) + init = "&init=true" + req_data = await client.post(persistent_vars["sillyGirl"]['url']+"/pgm?token="+persistent_vars["sillyGirl"]['token']+init, json=data) except Exception as e: return if not req_data.status_code == 200: @@ -96,10 +95,6 @@ async def poll(data): replies = json.loads(req_data.text) results = [] for reply in replies: - if reply["whiltelist"] != "": - persistent_vars["sillyGirl"]['whiltelist'] = reply["whiltelist"] - await persistent_vars["sillyGirl"]['context'].edit("获取白名单中...") - continue if reply["delete"]: try: await bot.edit_message(reply["chat_id"], reply["id"], "打错字了,呱呱~") @@ -142,4 +137,5 @@ async def poll(data): await persistent_vars["sillyGirl"]['context'].edit("傻妞连接成功,愉快玩耍吧。") await persistent_vars["sillyGirl"]['context'].delete() except Exception as e: + return