.
This commit is contained in:
parent
533505465d
commit
9e2efe6320
@ -10,44 +10,53 @@ import { EChangeType, IRecordInfo } from './interface';
|
||||
export class NotifyService {
|
||||
private _itemTemplate = '[channel][uids]等玩家的[itemId][type量]已超过预警值,请注意处理';
|
||||
private _rechargeTemplate = '[channel][uids]等玩家的充值已超过预警值,请注意处理';
|
||||
|
||||
async notifyXianYu(data: IRecordInfo[], channel: string, type: EChangeType) {
|
||||
if (data.length === 0) return;
|
||||
|
||||
const uids = data.map(d => d.uid).join(',');
|
||||
const content = this.formatItem(channel, uids, '仙玉', type);
|
||||
console.log(content, data);
|
||||
await this.sendDD(content);
|
||||
}
|
||||
async notifyItem(data: IRecordInfo[], channel: string, itemId: number, type: EChangeType) {
|
||||
if (data.length === 0) return;
|
||||
|
||||
const uids = data.map(d => d.uid).join(',');
|
||||
const content = this.formatItem(channel, uids, itemId, type);
|
||||
console.log(content, data);
|
||||
await this.sendDD(content);
|
||||
}
|
||||
private records: Map<string, string[]> = new Map();
|
||||
|
||||
async notifyRecharge(data: IRecordInfo[], channel: string) {
|
||||
if (data.length === 0) return;
|
||||
|
||||
const uids = data.map(d => d.uid).join(',');
|
||||
const key = `${channel}-recharge`;
|
||||
const old = this.records.has(key) ? this.records.get(key) : [];
|
||||
|
||||
const uids = data.map(d => d.uid).filter(uid => !old.includes(uid));
|
||||
if (uids.length === 0) return;
|
||||
|
||||
const content = this.formatRecharge(channel, uids);
|
||||
console.log(content, data);
|
||||
console.log(content);
|
||||
|
||||
await this.sendDD(content);
|
||||
old.push(...uids);
|
||||
this.records.set(key, old);
|
||||
}
|
||||
|
||||
private formatItem(channel: string, uids: string, itemId: string | number, type: EChangeType) {
|
||||
async notifyItemChange(data: IRecordInfo[], channel: string, itemId: number | string, type: EChangeType) {
|
||||
if (data.length === 0) return;
|
||||
|
||||
const key = `${channel}-${type}`;
|
||||
const old = this.records.has(key) ? this.records.get(key) : [];
|
||||
|
||||
const uids = data.map(d => d.uid).filter(uid => !old.includes(uid));
|
||||
if (uids.length === 0) return;
|
||||
|
||||
const content = this.formatItem(channel, uids, itemId, type);
|
||||
console.log(content);
|
||||
|
||||
await this.sendDD(content);
|
||||
old.push(...uids);
|
||||
this.records.set(key, old);
|
||||
}
|
||||
|
||||
private formatItem(channel: string, uids: string[], itemId: string | number, type: EChangeType) {
|
||||
return this._itemTemplate
|
||||
.replace('channel', channel)
|
||||
.replace('uids', uids)
|
||||
.replace('uids', uids.join(','))
|
||||
.replace('itemId', itemId as string)
|
||||
.replace('type', type === 'use' ? '消耗' : '获取')
|
||||
}
|
||||
private formatRecharge(channel: string, uids: string) {
|
||||
private formatRecharge(channel: string, uids: string[]) {
|
||||
return this._rechargeTemplate
|
||||
.replace('channel', channel)
|
||||
.replace('uids', uids);
|
||||
.replace('uids', uids.join(','));
|
||||
}
|
||||
|
||||
private async sendDD(content: string) {
|
||||
|
@ -54,7 +54,7 @@ export class TaService {
|
||||
const eventName = type === 'use' ? 'use_xian_yu' : 'get_xian_yu';
|
||||
const sql = this.xianYuChangeSql(eventDb, date, eventName, limit);
|
||||
const res = await this.readData(apiSecret, sql);
|
||||
await this._notifyService.notifyXianYu(res, channel, type);
|
||||
await this._notifyService.notifyItemChange(res, channel, '仙玉', type);
|
||||
}
|
||||
|
||||
private async checkItem(config: ITaConfig, date: string, itemId: number, type: 'use' | 'get', limit: number) {
|
||||
@ -68,7 +68,7 @@ export class TaService {
|
||||
const sql = this.itemChangeSql(eventDb, date, itemId, eventName, limit);
|
||||
const res = await this.readData(apiSecret, sql);
|
||||
|
||||
await this._notifyService.notifyItem(res, channel, itemId, type);
|
||||
await this._notifyService.notifyItemChange(res, channel, itemId, type);
|
||||
}
|
||||
|
||||
private readConfig() {
|
||||
|
Loading…
Reference in New Issue
Block a user