Browse Source

fix: delete permanent media

develop
JS00000 1 year ago
parent
commit
40264bc9cb
4 changed files with 16 additions and 8 deletions
  1. +4
    -1
      channel/wechatmp/active_reply.py
  2. +4
    -1
      channel/wechatmp/passive_reply.py
  3. +2
    -2
      channel/wechatmp/wechatmp_channel.py
  4. +6
    -4
      channel/wechatmp/wechatmp_client.py

+ 4
- 1
channel/wechatmp/active_reply.py View File

@@ -42,7 +42,10 @@ class Query:
message, 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( context = channel._compose_context(
ContextType.TEXT, message, isgroup=False, desire_rtype=rtype, msg=wechatmp_msg ContextType.TEXT, message, isgroup=False, desire_rtype=rtype, msg=wechatmp_msg
) )


+ 4
- 1
channel/wechatmp/passive_reply.py View File

@@ -43,7 +43,10 @@ class Query:
and message_id not in channel.request_cnt # insert the godcmd and message_id not in channel.request_cnt # insert the godcmd
): ):
# The first query begin # 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( context = channel._compose_context(
ContextType.TEXT, message, isgroup=False, desire_rtype=rtype, msg=wechatmp_msg ContextType.TEXT, message, isgroup=False, desire_rtype=rtype, msg=wechatmp_msg
) )


+ 2
- 2
channel/wechatmp/wechatmp_channel.py View File

@@ -60,10 +60,10 @@ class WechatMPChannel(ChatChannel):
loop.run_forever() loop.run_forever()


async def delete_media(self, media_id): 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) await asyncio.sleep(10)
self.client.delete_permanent_media(media_id) 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): def send(self, reply: Reply, context: Context):
receiver = context["receiver"] receiver = context["receiver"]


+ 6
- 4
channel/wechatmp/wechatmp_client.py View File

@@ -117,13 +117,13 @@ class WechatMPClient:
"type": media_type "type": media_type
} }
files={"media": media_file} files={"media": media_file}
logger.info("[wechatmp] media {} uploaded".format(media_file))
ret = self.wechatmp_request( ret = self.wechatmp_request(
method="post", method="post",
url=url, url=url,
params=params, params=params,
files=files files=files
) )
logger.debug("[wechatmp] media {} uploaded".format(media_file))
return ret["media_id"] return ret["media_id"]




@@ -134,13 +134,13 @@ class WechatMPClient:
"type": media_type "type": media_type
} }
files={"media": media_file} files={"media": media_file}
logger.info("[wechatmp] media {} uploaded".format(media_file))
ret = self.wechatmp_request( ret = self.wechatmp_request(
method="post", method="post",
url=url, url=url,
params=params, params=params,
files=files files=files
) )
logger.debug("[wechatmp] permanent media {} uploaded".format(media_file))
return ret["media_id"] return ret["media_id"]




@@ -149,13 +149,13 @@ class WechatMPClient:
params={ params={
"access_token": self.get_access_token() "access_token": self.get_access_token()
} }
logger.info("[wechatmp] media {} deleted".format(media_id))
self.wechatmp_request( self.wechatmp_request(
method="post", method="post",
url=url, url=url,
params=params, 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): def clear_quota(self):
url="https://api.weixin.qq.com/cgi-bin/clear_quota" url="https://api.weixin.qq.com/cgi-bin/clear_quota"
@@ -168,6 +168,7 @@ class WechatMPClient:
params=params, params=params,
data={"appid": self.app_id} data={"appid": self.app_id}
) )
logger.debug("[wechatmp] API quata has been cleard")


def clear_quota_v2(self): def clear_quota_v2(self):
url="https://api.weixin.qq.com/cgi-bin/clear_quota/v2" url="https://api.weixin.qq.com/cgi-bin/clear_quota/v2"
@@ -176,3 +177,4 @@ class WechatMPClient:
url=url, url=url,
data={"appid": self.app_id, "appsecret": self.app_secret} data={"appid": self.app_id, "appsecret": self.app_secret}
) )
logger.debug("[wechatmp] API quata has been cleard")

Loading…
Cancel
Save