更新通知服务

This commit is contained in:
whyour
2021-09-16 21:01:29 +08:00
parent 27226e7222
commit 9534cda1f9
5 changed files with 35 additions and 20 deletions
+11 -3
View File
@@ -1,9 +1,10 @@
import { NotificationInfo } from '../data/notify';
import { Service, Inject } from 'typedi';
import winston from 'winston';
import AuthService from './auth';
@Service()
export default class NotifyService {
export default class NotificationService {
private modeMap = new Map([
['goCqHttpBot', this.goCqHttpBot],
['serverChan', this.serverChan],
@@ -17,14 +18,21 @@ export default class NotifyService {
['email', this.email],
]);
private title = '';
private content = '';
private params!: Omit<NotificationInfo, 'type'>;
constructor(
@Inject('logger') private logger: winston.Logger,
private authService: AuthService,
) {}
private async notify() {
const { type } = await this.authService.getNotificationMode();
public async notify(title: string, content: string) {
const { type, ...rest } = await this.authService.getNotificationMode();
if (type) {
this.title = title;
this.content = content;
this.params = rest;
const notificationModeAction = this.modeMap.get(type);
notificationModeAction?.call(this);
}