From 047bd00545253406ab324dc8be083770f43b643d Mon Sep 17 00:00:00 2001 From: Ching Date: Fri, 7 Jan 2022 11:59:11 +0800 Subject: [PATCH] =?UTF-8?q?feat(dodo.py):=20[M]=20=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E4=B8=8A=E4=B8=80=E6=9D=A1=E5=92=8C=E5=88=A0=E9=99=A4=E4=B8=8A?= =?UTF-8?q?=E4=B8=80=E6=9D=A1=E5=98=9F=E5=98=9F=E7=9A=84=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [M] 增加上一条和删除上一条嘟嘟的功能 Signed-off-by: Ching --- scripts/dodo.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/scripts/dodo.py b/scripts/dodo.py index 54a0f36..9b534dd 100644 --- a/scripts/dodo.py +++ b/scripts/dodo.py @@ -19,6 +19,7 @@ APP_SECRET = 'yuSQenId0VfvwdZ3qL9wMd8FpCMEUL0u' ENCRYPT_KEY = '4XfjcA5xou3pztBD4g5V7dgHtr0BBYDE' EVENT_TYPE = ['im.message.receive_v1'] ADD_GROUP_NAME = True +KEDAI_ID = '107263380636355825' logging.basicConfig(filename='/root/develop/log/dodo.log', level=logging.INFO) logger = logging.getLogger('/root/develop/log/dodo.log') @@ -166,11 +167,13 @@ class RequestHandler(BaseHTTPRequestHandler): # 机器人回复收到的消息 text = json.loads(msg.get('content')).get('text') + orig_text = text if msg.get('chat_type') == 'group' and msg.get('mentions'): open_id = {"open_chat_id": msg.get("chat_id")} for mention in msg.get('mentions'): text = text.replace(mention['key'], '') text = text.lstrip() + orig_text = text if ADD_GROUP_NAME: group_name = get_group_name(msg.get("chat_id")) text = '%s #%s' % (text, group_name) @@ -178,6 +181,24 @@ class RequestHandler(BaseHTTPRequestHandler): open_id = {"open_id": event.get("sender", {}).get( 'sender_id', {}).get('open_id')} self.response("") + if orig_text == '/last': + try: + statuses = mastodon.account_statuses(KEDAI_ID, limit=1) + self.msg_compoment(access_token, open_id, + statuses[0]['content']) + except Exception as exc: + logger.error('operation error: %s', str(exc)) + elif orig_text == '/del': + try: + statuses = mastodon.account_statuses(KEDAI_ID, limit=1) + Mastodon.status_delete(statuses[0]['id']) + self.msg_compoment(access_token, open_id, + '已删除: ' + statuses[0]['content']) + except Exception as exc: + logger.error('operation error: %s', str(exc)) + + + try: toot_resp = mastodon.status_post(text) if toot_resp.get('id'):