import TgBaseService from './tgbase'; /** * tg机器人 */ export default class TgbotService extends TgBaseService { async tgTest() { return await this.reqTgbotApi('test', {}); } /** * bot list */ async list() { return await this.getRepo().admin.tg.TgBot.find(); } /** * bot count */ async count() { return await this.getRepo().admin.tg.TgBot.count(); } /** * 分页加载bot */ async page(page: number, count: number) { return await this.getRepo().admin.tg.TgBot.find({ order: { id: 'ASC', }, take: count, skip: page * count, }); } /** * bot add */ async add(param:any) { const { botId, username, name, token, status, description } = param; await this.getRepo().admin.tg.TgBot.insert({ botId, username, name, token, status, description }); // 通知api进程创建bot监听 if (status) await this.reqTgbotApi('addTgBot', botId); else await this.reqTgbotApi('removeTgBot', botId); return { botId }; } /** * bot update */ async update(param:any) { const { id, botId, username, name, token, status, description } = param; const bot = await this.getRepo().admin.tg.TgBot.save({ id, botId, username, name, token, status, description }); // 通知api进程创建bot监听 if (status) await this.reqTgbotApi('addTgBot', botId); else await this.reqTgbotApi('removeTgBot', botId); return bot; } /** * bot del */ async delete(id:number) { const bot = await this.getRepo().admin.tg.TgBot.findOne({ id }); if (bot != null) { await this.getRepo().admin.tg.TgBot.delete(id); await this.reqTgbotApi('removeTgBot', bot.botId); } return id; } }