From 40264bc9cb611c9497202b20b29c6ec7e1527087 Mon Sep 17 00:00:00 2001 From: JS00000 Date: Thu, 20 Apr 2023 12:03:48 +0800 Subject: [PATCH] fix: delete permanent media --- channel/wechatmp/active_reply.py | 5 ++++- channel/wechatmp/passive_reply.py | 5 ++++- channel/wechatmp/wechatmp_channel.py | 4 ++-- channel/wechatmp/wechatmp_client.py | 10 ++++++---- 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/channel/wechatmp/active_reply.py b/channel/wechatmp/active_reply.py index c700ca3..d8a8dde 100644 --- a/channel/wechatmp/active_reply.py +++ b/channel/wechatmp/active_reply.py @@ -42,7 +42,10 @@ class Query: message, ) ) - rtype = ReplyType.VOICE if wechatmp_msg.msg_type == "voice" else None + if (wechatmp_msg.msg_type == "voice" and conf().get("voice_reply_voice") == True): + rtype = ReplyType.VOICE + else: + rtype = None context = channel._compose_context( ContextType.TEXT, message, isgroup=False, desire_rtype=rtype, msg=wechatmp_msg ) diff --git a/channel/wechatmp/passive_reply.py b/channel/wechatmp/passive_reply.py index f489270..eca94ba 100644 --- a/channel/wechatmp/passive_reply.py +++ b/channel/wechatmp/passive_reply.py @@ -43,7 +43,10 @@ class Query: and message_id not in channel.request_cnt # insert the godcmd ): # The first query begin - rtype = ReplyType.VOICE if wechatmp_msg.msg_type == "voice" else None + if (wechatmp_msg.msg_type == "voice" and conf().get("voice_reply_voice") == True): + rtype = ReplyType.VOICE + else: + rtype = None context = channel._compose_context( ContextType.TEXT, message, isgroup=False, desire_rtype=rtype, msg=wechatmp_msg ) diff --git a/channel/wechatmp/wechatmp_channel.py b/channel/wechatmp/wechatmp_channel.py index 1c83149..9780048 100644 --- a/channel/wechatmp/wechatmp_channel.py +++ b/channel/wechatmp/wechatmp_channel.py @@ -60,10 +60,10 @@ class WechatMPChannel(ChatChannel): loop.run_forever() async def delete_media(self, media_id): - logger.info("[wechatmp] media {} will be deleted in 10s".format(media_id)) + logger.debug("[wechatmp] permanent media {} will be deleted in 10s".format(media_id)) await asyncio.sleep(10) self.client.delete_permanent_media(media_id) - logger.info("[wechatmp] media {} has been deleted".format(media_id)) + logger.info("[wechatmp] permanent media {} has been deleted".format(media_id)) def send(self, reply: Reply, context: Context): receiver = context["receiver"] diff --git a/channel/wechatmp/wechatmp_client.py b/channel/wechatmp/wechatmp_client.py index 321726d..96ebddb 100644 --- a/channel/wechatmp/wechatmp_client.py +++ b/channel/wechatmp/wechatmp_client.py @@ -117,13 +117,13 @@ class WechatMPClient: "type": media_type } files={"media": media_file} - logger.info("[wechatmp] media {} uploaded".format(media_file)) ret = self.wechatmp_request( method="post", url=url, params=params, files=files ) + logger.debug("[wechatmp] media {} uploaded".format(media_file)) return ret["media_id"] @@ -134,13 +134,13 @@ class WechatMPClient: "type": media_type } files={"media": media_file} - logger.info("[wechatmp] media {} uploaded".format(media_file)) ret = self.wechatmp_request( method="post", url=url, params=params, files=files ) + logger.debug("[wechatmp] permanent media {} uploaded".format(media_file)) return ret["media_id"] @@ -149,13 +149,13 @@ class WechatMPClient: params={ "access_token": self.get_access_token() } - logger.info("[wechatmp] media {} deleted".format(media_id)) self.wechatmp_request( method="post", url=url, params=params, - data={"media_id": media_id} + data=json.dumps({"media_id": media_id}, ensure_ascii=False).encode("utf8") ) + logger.debug("[wechatmp] permanent media {} deleted".format(media_id)) def clear_quota(self): url="https://api.weixin.qq.com/cgi-bin/clear_quota" @@ -168,6 +168,7 @@ class WechatMPClient: params=params, data={"appid": self.app_id} ) + logger.debug("[wechatmp] API quata has been cleard") def clear_quota_v2(self): url="https://api.weixin.qq.com/cgi-bin/clear_quota/v2" @@ -176,3 +177,4 @@ class WechatMPClient: url=url, data={"appid": self.app_id, "appsecret": self.app_secret} ) + logger.debug("[wechatmp] API quata has been cleard")