mirror of
https://github.com/zhayujie/chatgpt-on-wechat.git
synced 2026-07-20 13:47:15 +08:00
fix: delete permanent media
This commit is contained in:
@@ -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
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -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
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -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"]
|
||||||
|
|||||||
@@ -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")
|
||||||
|
|||||||
Reference in New Issue
Block a user