mirror of
https://github.com/whyour/qinglong.git
synced 2026-07-01 04:40:38 +08:00
增加chronocat无头模式的QQNT推送 用于无法使go-cqhttp的接替 (#2141)
* 增加chronocat无头模式的QQNT推送 * Chronocat发送时没有配置群号或个人消息号发送出错 * 增加系统通知、去除注释 * 增加系统通知 --------- Co-authored-by: child <wulincheng@javalc.com>
This commit is contained in:
+66
-7
@@ -1,12 +1,12 @@
|
||||
import { NotificationInfo } from '../data/notify';
|
||||
import { Service, Inject } from 'typedi';
|
||||
import winston from 'winston';
|
||||
import UserService from './user';
|
||||
import got from 'got';
|
||||
import nodemailer from 'nodemailer';
|
||||
import crypto from 'crypto';
|
||||
import got from 'got';
|
||||
import { HttpProxyAgent, HttpsProxyAgent } from 'hpagent';
|
||||
import nodemailer from 'nodemailer';
|
||||
import { Inject, Service } from 'typedi';
|
||||
import winston from 'winston';
|
||||
import { parseBody, parseHeaders } from '../config/util';
|
||||
import { NotificationInfo } from '../data/notify';
|
||||
import UserService from './user';
|
||||
|
||||
@Service()
|
||||
export default class NotificationService {
|
||||
@@ -31,6 +31,7 @@ export default class NotificationService {
|
||||
['pushMe', this.pushMe],
|
||||
['webhook', this.webhook],
|
||||
['lark', this.lark],
|
||||
['chronocat', this.chronocat],
|
||||
]);
|
||||
|
||||
private title = '';
|
||||
@@ -195,7 +196,8 @@ export default class NotificationService {
|
||||
}
|
||||
|
||||
private async bark() {
|
||||
let { barkPush, barkIcon, barkSound, barkGroup, barkLevel, barkUrl } = this.params;
|
||||
let { barkPush, barkIcon, barkSound, barkGroup, barkLevel, barkUrl } =
|
||||
this.params;
|
||||
if (!barkPush.startsWith('http')) {
|
||||
barkPush = `https://api.day.app/${barkPush}`;
|
||||
}
|
||||
@@ -588,6 +590,63 @@ export default class NotificationService {
|
||||
}
|
||||
}
|
||||
|
||||
private async chronocat() {
|
||||
const { chronocatURL, chronocatQQ, chronocatToekn } = this.params;
|
||||
try {
|
||||
const user_ids = chronocatQQ
|
||||
.match(/user_id=(\d+)/g)
|
||||
?.map((match: any) => match.split('=')[1]);
|
||||
const group_ids = chronocatQQ
|
||||
.match(/group_id=(\d+)/g)
|
||||
?.map((match: any) => match.split('=')[1]);
|
||||
|
||||
const url = `${chronocatURL}/api/message/send`;
|
||||
const headers = {
|
||||
'Content-Type': 'application/json',
|
||||
Authorization: `Bearer ${chronocatToekn}`,
|
||||
};
|
||||
|
||||
for (const [chat_type, ids] of [
|
||||
[1, user_ids],
|
||||
[2, group_ids],
|
||||
]) {
|
||||
if (!ids) {
|
||||
continue;
|
||||
}
|
||||
let _ids: any = ids;
|
||||
for (const chat_id of _ids) {
|
||||
const data = {
|
||||
peer: {
|
||||
chatType: chat_type,
|
||||
peerUin: chat_id,
|
||||
},
|
||||
elements: [
|
||||
{
|
||||
elementType: 1,
|
||||
textElement: {
|
||||
content: `${this.title}\n\n${this.content}`,
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
const res: any = await got.post(url, {
|
||||
...this.gotOption,
|
||||
json: data,
|
||||
headers,
|
||||
});
|
||||
if (res.body === 'success') {
|
||||
return true;
|
||||
} else {
|
||||
throw new Error(res.body);
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
} catch (error: any) {
|
||||
throw new Error(error.response ? error.response.body : error);
|
||||
}
|
||||
}
|
||||
|
||||
private async webhook() {
|
||||
const {
|
||||
webhookUrl,
|
||||
|
||||
Reference in New Issue
Block a user