Skip to content

Commit

Permalink
🐛 新增推送,修复图片
Browse files Browse the repository at this point in the history
  • Loading branch information
Charles-Hello committed Sep 9, 2023
1 parent dc25163 commit b7985c7
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 6 deletions.
3 changes: 3 additions & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,6 @@ log_level = "INFO"
log_days = 10
# 文件缓存天数,为0则不清理缓存,每天凌晨清理
cache_days = 3


push_plus_token = ""
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ __pycache__/

# C extensions
*.so

# Distribution / packaging
.Python
build/
Expand Down Expand Up @@ -108,7 +107,7 @@ venv/
ENV/
env.bak/
venv.bak/

.env
# Spyder project settings
.spyderproject
.spyproject
Expand Down
30 changes: 28 additions & 2 deletions wechatbot_client/action_manager/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from pathlib import Path
from sys import exit
from typing import Callable, Literal, Optional, ParamSpec, TypeVar, Union

import requests
from pydantic import BaseModel

from wechatbot_client.com_wechat import ComWechatApi
Expand Down Expand Up @@ -89,15 +89,40 @@ def init(self, file_manager: FileManager, config: Config) -> None:
exit(0)
log("SUCCESS", "<g>登录完成...</g>")


def push(self,config: Config):
headers = {
'Accept': '*/*',
'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',
'Cache-Control': 'no-cache',
'Connection': 'keep-alive',
'Content-Type': 'application/json;charset=UTF-8',
}
json_data = {
'token': config.push_plus_token,
'title': '微信登录',
'content': '快去登录!!',
'template': 'html',
'channel': 'wechat',
'webhook': '',
}

requests.post('https://www.pushplus.plus/api/send', headers=headers, json=json_data)


def wait_for_login(self) -> bool:
"""
等待登录
"""
count =0
while True:
try:
if self.com_api.is_wechat_login():
return True
time.sleep(1)
count += count
if count % 300 == 0:
self.push(Config)
except KeyboardInterrupt:
return False

Expand Down Expand Up @@ -613,7 +638,8 @@ async def upload_file(
)
if isinstance(data, str):
data = b64decode(data)
file_id = await self.file_manager.cache_file_id_from_data(data, name)
new_image_data = b64decode(data)
file_id = await self.file_manager.cache_file_id_from_data(new_image_data, name)
return ActionResponse(status="ok", retcode=0, data={"file_id": file_id})

@standard_action
Expand Down
3 changes: 2 additions & 1 deletion wechatbot_client/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ class Config(BaseConfig):
"""日志保存天数"""
cache_days: int = 3
"""文件缓存天数"""

push_plus_token :str= ""
"""push_plus的token"""
class Config:
extra = "allow"
5 changes: 4 additions & 1 deletion 备忘录.py → 备忘录.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@


git tag -a v0.0.6 -m "新增删除文件逻辑"
git push origin v0.0.6
git push origin v0.0.6



0 comments on commit b7985c7

Please sign in to comment.