FlowEngine
Processa interações e gerencia estados
Importação
typescript
import { FlowEngine, FlowRegistry, MemoryStore } from 'discord-flow';Construtor
typescript
1const registry = new FlowRegistry();2const store = new MemoryStore();3const engine = new FlowEngine(registry, store);Parâmetros
registry
Instância de FlowRegistry com flows definidos
store
Instância de Store para persistência de estados
Métodos
process()
Processa um evento de interação e retorna a resposta.
typescript
1engine.process(event: FlowEvent): Promise 2 3interface FlowEvent {4 type: 'command' | 'button' | 'modal' | 'select';5 key: string;6 interaction: DiscordInteraction;7}8 9// Exemplo10const response = await engine.process({11 type: 'command',12 key: 'ping',13 interaction: discordInteraction14});getRegistry()
Retorna o registry associado ao engine.
typescript
1engine.getRegistry(): FlowRegistry2 3// Exemplo4const registry = engine.getRegistry();5const commands = registry.getCommands();Stores
O engine aceita diferentes implementações de store:
MemoryStore
Store em memória (para desenvolvimento).
typescript
1import { MemoryStore } from 'discord-flow';2 3const store = new MemoryStore();MongoStore
Store com MongoDB (para produção).
typescript
1import { MongoStore } from '@discord-flow/store';2import { MongoClient } from 'mongodb';3 4const client = new MongoClient(process.env.MONGO_URI);5const db = client.db('mybot');6const store = new MongoStore(db);