import { CommandSet, Action, ActionType } from "src/model/command"; import { Message } from "discord.js"; import { getRepository } from "typeorm"; import { RandomMessageReaction } from "@shared/db/entity/RandomMesssageReaction"; import { client } from "src/client"; const timeout = (ms: number) => new Promise(r => setTimeout(r, ms)); @CommandSet export class RandomReact { @Action(ActionType.MESSAGE) async showHelp(actionsDone: boolean, msg: Message) { if(actionsDone) return false; let repo = getRepository(RandomMessageReaction); let reactInfo = await repo.findOne({ where: { userId: msg.author.id } }); if(!reactInfo) return false; let emote = client.bot.emojis.resolve(reactInfo.reactionEmoteId); if(!emote) return false; if(Math.random() < reactInfo.reactProbability) { await timeout(Math.random() * reactInfo.maxWaitMs); await msg.react(emote); } return false; } }