Skip to content

Commit

Permalink
fix: delete permanent media
Browse files Browse the repository at this point in the history
  • Loading branch information
JS00000 committed Apr 20, 2023
1 parent a777231 commit 40264bc
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
5 changes: 4 additions & 1 deletion channel/wechatmp/active_reply.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ def POST(self):
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
)
Expand Down
5 changes: 4 additions & 1 deletion channel/wechatmp/passive_reply.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ def POST(self):
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
)
Expand Down
4 changes: 2 additions & 2 deletions channel/wechatmp/wechatmp_channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ def start_loop(self, loop):
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"]
Expand Down
10 changes: 6 additions & 4 deletions channel/wechatmp/wechatmp_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,13 @@ def upload_media(self, media_type, media_file):
"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"]


Expand All @@ -134,13 +134,13 @@ def upload_permanent_media(self, media_type, media_file):
"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"]


Expand All @@ -149,13 +149,13 @@ def delete_permanent_media(self, media_id):
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"
Expand All @@ -168,6 +168,7 @@ def clear_quota(self):
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"
Expand All @@ -176,3 +177,4 @@ def clear_quota_v2(self):
url=url,
data={"appid": self.app_id, "appsecret": self.app_secret}
)
logger.debug("[wechatmp] API quata has been cleard")

0 comments on commit 40264bc

Please sign in to comment.