| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- 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;
- }
- }
|