dead_chat.ts 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. import { getRepository } from "typeorm";
  2. import { DeadChatReply } from "@shared/db/entity/DeadChatReply";
  3. import { Message } from "discord.js";
  4. import { Event, BotEventData, Plugin } from "src/model/plugin";
  5. const triggers = [
  6. "dead server",
  7. "dead chat",
  8. "ded chat",
  9. "ded server"
  10. ];
  11. @Plugin
  12. export class DeadChat {
  13. @Event("message")
  14. async onMessage(data: BotEventData, msg: Message): Promise<void> {
  15. if (data.actionsDone)
  16. return;
  17. const lowerContent = msg.cleanContent.trim().toLowerCase();
  18. if (!triggers.some(s => lowerContent.includes(s)))
  19. return;
  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;
  27. msg.channel.send(reply[0].message);
  28. data.actionsDone = true;
  29. }
  30. }