tg 推送测试

This commit is contained in:
Womsxd 2022-01-25 15:03:53 +08:00
parent 9dcb3f0f4e
commit 47280f1124
No known key found for this signature in database
GPG Key ID: 0FE76418EE689B68
2 changed files with 19 additions and 2 deletions

View File

@ -1,6 +1,6 @@
[setting]
enable=false
#共有 cqhttp ftqq(sever酱) pushplus
#共有 cqhttp ftqq(sever酱) pushplus telegram
push_server=cqhttp
#server酱和pushplus的推送token
push_token=123456
@ -9,4 +9,9 @@ push_token=123456
#cqhttp的服务端地址
cqhttp_url=http://127.0.0.1:5000/send_private_msg
#推送给谁
cqhttp_qq=10001
cqhttp_qq=10001
[telegram]
api_url=api.telegram.org
bot_token=123465:abcdefg
chat_id=123456

12
push.py
View File

@ -22,6 +22,16 @@ def title(status):
return "「米游社脚本」执行失败!"
def telegram(status, push_message):
http.post(
url="https://{}/bot{}/sendMessage".format(cfg.get('telegram', 'api_url'), cfg.get('telegram', 'bot_token')),
data={
"chat_id": cfg.get('telegram', 'chat_id'),
"text": title(status) + "\r\n" + push_message
}
)
def ftqq(status, push_message):
http.post(
url="https://sctapi.ftqq.com/{}.send".format(cfg.get('setting', 'push_token')),
@ -66,5 +76,7 @@ def push(status, push_message):
ftqq(status, push_message)
elif push_server == "pushplus":
pushplus(status, push_message)
elif push_server == "telegram":
telegram(status, push_message)
log.info("推送完毕......")
return 0