Anforderungen  |   Konzepte  |   Entwurf  |   Entwicklung  |   Qualitätssicherung  |   Lebenszyklus  |   Steuerung
 
 
 
 


Quelle  message-gating.ts

  Sprache: JAVA
 

Spracherkennung für: .ts vermutete Sprache: Unknown {[0] [0] [0]} [Methode: Schwerpunktbildung, einfache Gewichte, sechs Dimensionen]

/**
 * Group message gating — three-layer access control for group messages.
 *
 * 1. `ignoreOtherMentions` — skip messages that @other bots, not this one.
 * 2. `shouldBlock` — enforce allowFrom whitelist at the group level.
 * 3. `mentionGating` — require explicit @bot mention in group chats.
 *
 * All functions are **pure** (no side effects, no I/O), making them easy to
 * test and safe to share between the built-in and standalone versions.
 */

/** Result of the group message gate evaluation. */
export interface GateResult {
  /** Whether the message should be blocked (i.e. not processed). */
  blocked: boolean;
  /** Reason for blocking (for logging). */
  reason?: string;
  /** Whether the sender is authorized for slash commands. */
  commandAuthorized: boolean;
}

/** Configuration relevant to group message gating. */
export interface GroupGateConfig {
  /** Normalized allowFrom list (uppercase, `qqbot:` prefix stripped). */
  normalizedAllowFrom: string[];
  /**
   * Whether to ignore messages that mention other bots.
   * When true, messages containing @mentions for other bot IDs are silently dropped.
   */
  ignoreOtherMentions?: boolean;
}

/**
 * Evaluate the group message gate for one inbound message.
 *
 * @param senderId - The sender's openid (raw, not normalized).
 * @param config - Group gating configuration.
 * @returns The gate evaluation result.
 */
export function resolveGroupMessageGate(senderId: string, config: GroupGateConfig): GateResult {
  const { normalizedAllowFrom } = config;

  // Normalize the sender ID for comparison.
  const normalizedSenderId = senderId.replace(/^qqbot:/i, "").toUpperCase();

  // Open gate: empty allowFrom or wildcard means everyone is allowed.
  const allowAll = normalizedAllowFrom.length === 0 || normalizedAllowFrom.some((e) => e === "*");

  const commandAuthorized = allowAll || normalizedAllowFrom.includes(normalizedSenderId);

  return {
    blocked: false,
    commandAuthorized,
  };
}

/**
 * Normalize an allowFrom list by stripping `qqbot:` prefixes and uppercasing.
 *
 * @param allowFrom - Raw allowFrom config entries.
 * @returns Normalized entries for comparison.
 */
export function normalizeAllowFrom(allowFrom: Array<string | number> | undefined | null): string[] {
  if (!allowFrom) {
    return [];
  }
  return allowFrom
    .map((entry) => String(entry).trim())
    .filter(Boolean)
    .map((entry) => entry.replace(/^qqbot:/i, ""))
    .map((entry) => entry.toUpperCase());
}

¤ Dauer der Verarbeitung: 0.1 Sekunden  (vorverarbeitet am  2026-04-27) ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

Beweissystem der NASA

Beweissystem Isabelle

NIST Cobol Testsuite

Cephes Mathematical Library

Wiener Entwicklungsmethode

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.






                                                                                                                                                                                                                                                                                                                                                                                                     


Neuigkeiten

     Aktuelles
     Motto des Tages

Software

     Produkte
     Quellcodebibliothek

Aktivitäten

     Artikel über Sicherheit
     Anleitung zur Aktivierung von SSL

Muße

     Gedichte
     Musik
     Bilder

Jenseits des Üblichen ....
    

Besucherstatistik

Besucherstatistik

Monitoring

Montastic status badge