262 lines · 9.5 KB
import {
  countActiveAddresses,
  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,
} from "../../core/commands.ts";

const RATE_LIMIT_MESSAGE = "Slow down a moment, then try again.";
const NOT_PRIVATE_MESSAGE = "Message me directly (not in a group) to manage your addresses.";

export interface TelegramUpdate {
  message?: {
    text?: string;
    chat: { id: number; type: string };
    from?: { id: number };
  };
}

export interface TelegramReply {
  chatId: string;
  text: string;
}

// Splits off just the command token ("/new", stripping a group chat's
// "@BotName" disambiguation suffix if present). Everything else about a