dead_chat.ts 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import { getRepository } from "typeorm";
  2. import { DeadChatReply } from "@shared/db/entity/DeadChatReply";
  3. import { CommandSet, Action, ActionType } from "src/model/command";
  4. import { Message } from "discord.js";
  5. const triggers = [
  6. "dead server",
  7. "dead chat",
  8. "ded chat",
  9. "ded server"
  10. ];
  11. @CommandSet
  12. export class DeadChat {
  13. @Action(ActionType.MESSAGE)
  14. async onMessage(actionsDone: boolean, msg: Message, content: string): Promise<boolean> {
  15. if (actionsDone)
  16. return false;
  17. const lowerContent = content.toLowerCase();
  18. if (!triggers.some(s => lowerContent.includes(s)))
  19. return false;
  20. const repo = getRepository(DeadChatReply);
  21. const reply = await repo.query(` select message
  22. from dead_chat_reply
  23. order by random()
  24. limit 1`) as DeadChatReply[];
  25. if (reply.length == 0)
  26. return false;
  27. msg.channel.send(reply[0].message);
  28. return true;
  29. }
  30. }