Cuu.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
1.4 KiB

  1. /* eslint-disable import/prefer-default-export */
  2. /* eslint-disable @typescript-eslint/no-unsafe-call */
  3. /* eslint-disable @typescript-eslint/no-unsafe-assignment */
  4. /* eslint-disable @typescript-eslint/no-unsafe-member-access */
  5. /* eslint-disable @typescript-eslint/no-unsafe-return */
  6. import { ChannelType } from 'discord.js';
  7. import CLIENT from '../client';
  8. import * as anime from '../functions/anime';
  9. import * as meme from '../functions/meme';
  10. import post from '../commands/post';
  11. import help from '../commands/help';
  12. CLIENT.on('messageCreate', async (message) => {
  13. if (!CLIENT.user) {
  14. return;
  15. }
  16. if (message.author.id === CLIENT.user.id) {
  17. // Do not listen to own messages.
  18. return;
  19. }
  20. const content = message.content?.replaceAll(/\s\s+/g, ' ').toLowerCase() ?? '';
  21. if (message.channel.type === ChannelType.DM) {
  22. const [command] = content.split(' ');
  23. if (command === 'save') {
  24. await anime.queueImage(message);
  25. }
  26. return;
  27. }
  28. if (content.startsWith(`<@!${CLIENT.user.id}>`) || content.startsWith(`<@${CLIENT.user.id}>`)) {
  29. const [, command, ...args] = content.split(' ');
  30. if (command === 'post') {
  31. await post(message, ...args);
  32. return;
  33. }
  34. if (command === 'help') {
  35. await help(message);
  36. return;
  37. }
  38. return;
  39. }
  40. await meme.listenForKeywordsAndReply(message);
  41. await anime.listenForImagesAndReply(message);
  42. });