294 lines · 10.5 KB
import {
  countActiveAddresses,
  getAddress,
  extendAddress,
  getExpiryReminderPreference,
  listActiveAddresses,
  revokeAddress,
  setAddressNote,
  setExpiryReminderPreference,
} from "../../core/db.ts";
import { checkAndIncrement } from "../../core/ratelimit.ts";
import type { SqlExecutor } from "../../core/storage.ts";
import type { OwnerRef } from "../../core/types.ts";
import type { CommandConfig } from "../../core/config.ts";
import {
  BAD_EXPIRY_MESSAGE,
  type CreateAddressFn,
  describeExpiry,
  MAX_NOTE_LENGTH,
  parseExpiry,
  resolveAddressIdentifier,
  previewTorchAll,
  TORCH_ALL_CANCEL,
  TORCH_ALL_KEYWORD,
  torchAllConfirmValue,
} from "../../core/commands.ts";

const RATE_LIMIT_MESSAGE = "Slow down a moment, then try again.";
// Slack rejects bare generic words as custom slash command names (and
// /remind collides with a real Slack built-in), so every command here is
// registered as /cm-<name>. Stripped back off before dispatch so the
// internal command names, rate-limit keys, and config vars stay identical
// to Discord/Telegram's.
const COMMAND_PREFIX = "cm-";
export const TORCH_ALL_ACTION_PREFIX = "torch_all:";

export interface SlackSlashCommandPayload {
  command: string;
  text: string;
  user_id: string;