KingRan 2022-03-06 22:10:58 +08:00
parent 04fe7656ac
commit 3f9bba537c
2 changed files with 102 additions and 100 deletions

View File

@ -31,7 +31,7 @@ const querystring = require('querystring');
const exec = require('child_process').exec; const exec = require('child_process').exec;
const $ = new Env(); const $ = new Env();
const timeout = 15000; //超时时间(单位毫秒) const timeout = 15000; //超时时间(单位毫秒)
console.log("加载sendNotify当前版本: 20220302"); console.log("加载sendNotify当前版本: 20220306");
// =======================================go-cqhttp通知设置区域=========================================== // =======================================go-cqhttp通知设置区域===========================================
//gobot_url 填写请求地址http://127.0.0.1/send_private_msg //gobot_url 填写请求地址http://127.0.0.1/send_private_msg
//gobot_token 填写在go-cqhttp文件设置的访问密钥 //gobot_token 填写在go-cqhttp文件设置的访问密钥
@ -1989,57 +1989,58 @@ function BarkNotify(text, desp, params = {}) {
} }
function tgBotNotify(text, desp) { function tgBotNotify(text, desp) {
return new Promise((resolve) => { return new Promise(resolve => {
if (TG_BOT_TOKEN && TG_USER_ID) { if (TG_BOT_TOKEN && TG_USER_ID) {
const options = { const options = {
url: `https://${TG_API_HOST}/bot${TG_BOT_TOKEN}/sendMessage`, url: `https://${TG_API_HOST}/bot${TG_BOT_TOKEN}/sendMessage`,
body: `chat_id=${TG_USER_ID}&text=${text}\n\n${desp}&disable_web_page_preview=true`, json: {
headers: { chat_id: `${TG_USER_ID}`,
'Content-Type': 'application/x-www-form-urlencoded', text: `${text}\n\n${desp}`,
}, disable_web_page_preview:true,
timeout, },
}; headers: {
if (TG_PROXY_HOST && TG_PROXY_PORT) { 'Content-Type': 'application/json',
const tunnel = require('tunnel'); },
const agent = { timeout
https: tunnel.httpsOverHttp({ }
proxy: { if (TG_PROXY_HOST && TG_PROXY_PORT) {
host: TG_PROXY_HOST, const tunnel = require("tunnel");
port: TG_PROXY_PORT * 1, const agent = {
proxyAuth: TG_PROXY_AUTH, https: tunnel.httpsOverHttp({
}, proxy: {
}), host: TG_PROXY_HOST,
}; port: TG_PROXY_PORT * 1,
Object.assign(options, { proxyAuth: TG_PROXY_AUTH
agent
});
} }
$.post(options, (err, resp, data) => { })
try {
if (err) {
console.log('telegram发送通知消息失败\n');
console.log(err);
} else {
data = JSON.parse(data);
if (data.ok) {
console.log('Telegram发送通知消息成功🎉。\n');
} else if (data.error_code === 400) {
console.log('请主动给bot发送一条消息并检查接收用户ID是否正确。\n');
} else if (data.error_code === 401) {
console.log('Telegram bot token 填写错误。\n');
}
}
} catch (e) {
$.logErr(e, resp);
}
finally {
resolve(data);
}
});
} else {
resolve();
} }
}); Object.assign(options, {agent})
}
$.post(options, (err, resp, data) => {
try {
if (err) {
console.log('telegram发送通知消息失败\n')
console.log(err);
} else {
data = JSON.parse(data);
if (data.ok) {
console.log('Telegram发送通知消息成功<E68890>。\n')
} else if (data.error_code === 400) {
console.log('请主动给bot发送一条消息并检查接收用户ID是否正确。\n')
} else if (data.error_code === 401) {
console.log('Telegram bot token 填写错误。\n')
}
}
} catch (e) {
$.logErr(e, resp);
} finally {
resolve(data);
}
})
} else {
resolve()
}
})
} }
function ddBotNotify(text, desp) { function ddBotNotify(text, desp) {

View File

@ -31,7 +31,7 @@ const querystring = require('querystring');
const exec = require('child_process').exec; const exec = require('child_process').exec;
const $ = new Env(); const $ = new Env();
const timeout = 15000; //超时时间(单位毫秒) const timeout = 15000; //超时时间(单位毫秒)
console.log("加载sendNotify当前版本: 20220302"); console.log("加载sendNotify当前版本: 20220306");
// =======================================go-cqhttp通知设置区域=========================================== // =======================================go-cqhttp通知设置区域===========================================
//gobot_url 填写请求地址http://127.0.0.1/send_private_msg //gobot_url 填写请求地址http://127.0.0.1/send_private_msg
//gobot_token 填写在go-cqhttp文件设置的访问密钥 //gobot_token 填写在go-cqhttp文件设置的访问密钥
@ -1989,57 +1989,58 @@ function BarkNotify(text, desp, params = {}) {
} }
function tgBotNotify(text, desp) { function tgBotNotify(text, desp) {
return new Promise((resolve) => { return new Promise(resolve => {
if (TG_BOT_TOKEN && TG_USER_ID) { if (TG_BOT_TOKEN && TG_USER_ID) {
const options = { const options = {
url: `https://${TG_API_HOST}/bot${TG_BOT_TOKEN}/sendMessage`, url: `https://${TG_API_HOST}/bot${TG_BOT_TOKEN}/sendMessage`,
body: `chat_id=${TG_USER_ID}&text=${text}\n\n${desp}&disable_web_page_preview=true`, json: {
headers: { chat_id: `${TG_USER_ID}`,
'Content-Type': 'application/x-www-form-urlencoded', text: `${text}\n\n${desp}`,
}, disable_web_page_preview:true,
timeout, },
}; headers: {
if (TG_PROXY_HOST && TG_PROXY_PORT) { 'Content-Type': 'application/json',
const tunnel = require('tunnel'); },
const agent = { timeout
https: tunnel.httpsOverHttp({ }
proxy: { if (TG_PROXY_HOST && TG_PROXY_PORT) {
host: TG_PROXY_HOST, const tunnel = require("tunnel");
port: TG_PROXY_PORT * 1, const agent = {
proxyAuth: TG_PROXY_AUTH, https: tunnel.httpsOverHttp({
}, proxy: {
}), host: TG_PROXY_HOST,
}; port: TG_PROXY_PORT * 1,
Object.assign(options, { proxyAuth: TG_PROXY_AUTH
agent
});
} }
$.post(options, (err, resp, data) => { })
try {
if (err) {
console.log('telegram发送通知消息失败\n');
console.log(err);
} else {
data = JSON.parse(data);
if (data.ok) {
console.log('Telegram发送通知消息成功🎉。\n');
} else if (data.error_code === 400) {
console.log('请主动给bot发送一条消息并检查接收用户ID是否正确。\n');
} else if (data.error_code === 401) {
console.log('Telegram bot token 填写错误。\n');
}
}
} catch (e) {
$.logErr(e, resp);
}
finally {
resolve(data);
}
});
} else {
resolve();
} }
}); Object.assign(options, {agent})
}
$.post(options, (err, resp, data) => {
try {
if (err) {
console.log('telegram发送通知消息失败\n')
console.log(err);
} else {
data = JSON.parse(data);
if (data.ok) {
console.log('Telegram发送通知消息成功<E68890>。\n')
} else if (data.error_code === 400) {
console.log('请主动给bot发送一条消息并检查接收用户ID是否正确。\n')
} else if (data.error_code === 401) {
console.log('Telegram bot token 填写错误。\n')
}
}
} catch (e) {
$.logErr(e, resp);
} finally {
resolve(data);
}
})
} else {
resolve()
}
})
} }
function ddBotNotify(text, desp) { function ddBotNotify(text, desp) {