{"version":3,"file":"autoreply.mjs","names":[],"sources":["../../src/modules/autoreply.ts"],"sourcesContent":["import {\n  ActionRowBuilder,\n  ButtonBuilder,\n  ButtonStyle,\n  type ClientUser,\n  type Message,\n  OAuth2Scopes,\n} from 'discord.js'\nimport { SleetModule } from 'sleetcord'\n\ninterface AutoreplyModuleOptions {\n  /**\n   * Buttons to add to the autoreply message, alongside the \"Invite Bot\" button (Max 4)\n   */\n  buttons?: ButtonBuilder[]\n  /**\n   * The content to send in the autoreply message\n   * @default `Use slash commands to interact with me, type \\`/\\` into your chat bar to see them.\\nDon't see them? Try reinviting me!`\n   */\n  content?: string\n}\n\nexport function makeAutoreplyModule({\n  buttons = [],\n  content,\n}: AutoreplyModuleOptions = {}): SleetModule {\n  let clientUserRegex: RegExp | null = null\n\n  async function handleMessageCreate(message: Message): Promise<unknown> {\n    if (message.author.bot) return\n\n    const { client } = message\n    const userRegex = lazyInitClientUserRegex(client.user)\n\n    if (userRegex.test(message.content)) {\n      const inviteLink = client.generateInvite({\n        scopes: client.application.installParams?.scopes ?? [\n          OAuth2Scopes.Bot,\n          OAuth2Scopes.ApplicationsCommands,\n        ],\n      })\n\n      const row = new ActionRowBuilder<ButtonBuilder>()\n      const inviteButton = new ButtonBuilder()\n        .setLabel('Invite Bot')\n        .setStyle(ButtonStyle.Link)\n        .setURL(inviteLink)\n\n      row.addComponents([inviteButton, ...buttons])\n\n      await message.reply({\n        content:\n          content ??\n          `Use slash commands to interact with me, type \\`/\\` into your chat bar to see them.\\nDon't see them? Try reinviting me!`,\n        components: [row],\n      })\n\n      return\n    }\n\n    return\n  }\n\n  function lazyInitClientUserRegex(user: ClientUser): RegExp {\n    clientUserRegex ??= new RegExp(`^<@!?${user.id}>$`)\n    return clientUserRegex\n  }\n\n  return new SleetModule(\n    {\n      name: 'autoreply',\n    },\n    {\n      messageCreate: handleMessageCreate,\n    },\n  )\n}\n"],"mappings":";;;AAsBA,SAAgB,oBAAoB,EAClC,UAAU,EAAE,EACZ,YAC0B,EAAE,EAAe;CAC3C,IAAI,kBAAiC;CAErC,eAAe,oBAAoB,SAAoC;AACrE,MAAI,QAAQ,OAAO,IAAK;EAExB,MAAM,EAAE,WAAW;AAGnB,MAFkB,wBAAwB,OAAO,KAAK,CAExC,KAAK,QAAQ,QAAQ,EAAE;GACnC,MAAM,aAAa,OAAO,eAAe,EACvC,QAAQ,OAAO,YAAY,eAAe,UAAU,CAClD,aAAa,KACb,aAAa,qBACd,EACF,CAAC;GAEF,MAAM,MAAM,IAAI,kBAAiC;GACjD,MAAM,eAAe,IAAI,eAAe,CACrC,SAAS,aAAa,CACtB,SAAS,YAAY,KAAK,CAC1B,OAAO,WAAW;AAErB,OAAI,cAAc,CAAC,cAAc,GAAG,QAAQ,CAAC;AAE7C,SAAM,QAAQ,MAAM;IAClB,SACE,WACA;IACF,YAAY,CAAC,IAAI;IAClB,CAAC;AAEF;;;CAMJ,SAAS,wBAAwB,MAA0B;AACzD,sBAAoB,IAAI,OAAO,QAAQ,KAAK,GAAG,IAAI;AACnD,SAAO;;AAGT,QAAO,IAAI,YACT,EACE,MAAM,aACP,EACD,EACE,eAAe,qBAChB,CACF"}