1 Star 0 Fork 98

Mei/JD-SHOPPER

forked from Q/JD-SHOPPER 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
message.py 2.19 KB
一键复制 编辑 原始数据 按行查看 历史
import json
import requests
from logger import logger
from config import global_config
def sendMessage(message):
enabled = global_config.getRaw("messenger", "enable")
if not enabled:
return
mode = global_config.getRaw("messenger", "mode")
if mode == "group":
groupid = global_config.getRaw("messenger", "group_id")
sendGroupMessage(message, groupid)
else:
userid = global_config.getRaw("messenger", "user_id")
sendFriendMessage(message, userid)
def sendFriendMessage(message, userid):
URL = global_config.getRaw("messenger", "server_address")
path = "sendFriendMessage"
try:
URL = "http://{}/{}".format(URL, path)
body = {
"sessionKey": "YourSession",
"target": userid,
"messageChain": [
{"type": "Plain", "text": message}
]
}
# sender = requests.post(URL, params = params, data=json.dumps(body))
sender = requests.post(URL, data=json.dumps(body))
mes = message.replace("\n", " ")
if len(mes) > 10:
mes = mes[:10] + "···"
logger.info("Send {}".format(mes))
# print(sender.request.url)
# sender.raise_for_status()
# print(sender.text)
return True
except:
logger.error("Message Send Failed")
return False
def sendGroupMessage(message, groupid):
URL = global_config.getRaw("messenger", "server_address")
path = "sendGroupMessage"
try:
URL = "http://{}/{}".format(URL, path)
body = {
"sessionKey": "YourSession",
"target": groupid,
"messageChain": [
{"type": "Plain", "text": message}
]
}
# sender = requests.post(URL, params = params, data=json.dumps(body))
sender = requests.post(URL, data=json.dumps(body))
mes = message.replace("\n", " ")
if len(mes) > 10:
mes = mes[:10] + "···"
logger.info("Send {}".format(mes))
# print(sender.request.url)
# sender.raise_for_status()
# print(sender.text)
return True
except:
logger.error("Message Send Failed")
return False
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/zhangwenping/JD-SHOPPER.git
git@gitee.com:zhangwenping/JD-SHOPPER.git
zhangwenping
JD-SHOPPER
JD-SHOPPER
master

搜索帮助