2026-03-16 00:40:32 -07:00
|
|
|
import {
|
2026-03-20 18:50:25 +00:00
|
|
|
discordMessageActions,
|
2026-03-16 00:40:32 -07:00
|
|
|
getThreadBindingManager,
|
|
|
|
|
resolveThreadBindingIdleTimeoutMs,
|
|
|
|
|
resolveThreadBindingInactivityExpiresAt,
|
|
|
|
|
resolveThreadBindingMaxAgeExpiresAt,
|
|
|
|
|
resolveThreadBindingMaxAgeMs,
|
|
|
|
|
setThreadBindingIdleTimeoutBySessionKey,
|
|
|
|
|
setThreadBindingMaxAgeBySessionKey,
|
|
|
|
|
unbindThreadBindingsBySessionKey,
|
2026-03-20 22:54:16 -07:00
|
|
|
} from "../../plugin-sdk/discord.js";
|
2026-03-17 08:37:02 -07:00
|
|
|
import {
|
|
|
|
|
createLazyRuntimeMethodBinder,
|
|
|
|
|
createLazyRuntimeSurface,
|
|
|
|
|
} from "../../shared/lazy-runtime.js";
|
2026-03-16 00:24:40 -07:00
|
|
|
import { createDiscordTypingLease } from "./runtime-discord-typing.js";
|
|
|
|
|
import type { PluginRuntimeChannel } from "./types-channel.js";
|
|
|
|
|
|
2026-03-17 00:58:46 -07:00
|
|
|
const loadRuntimeDiscordOps = createLazyRuntimeSurface(
|
|
|
|
|
() => import("./runtime-discord-ops.runtime.js"),
|
|
|
|
|
({ runtimeDiscordOps }) => runtimeDiscordOps,
|
|
|
|
|
);
|
|
|
|
|
|
2026-03-17 08:37:02 -07:00
|
|
|
const bindDiscordRuntimeMethod = createLazyRuntimeMethodBinder(loadRuntimeDiscordOps);
|
2026-03-17 00:58:46 -07:00
|
|
|
|
2026-03-17 08:37:02 -07:00
|
|
|
const auditChannelPermissionsLazy = bindDiscordRuntimeMethod(
|
|
|
|
|
(runtimeDiscordOps) => runtimeDiscordOps.auditChannelPermissions,
|
|
|
|
|
);
|
|
|
|
|
const listDirectoryGroupsLiveLazy = bindDiscordRuntimeMethod(
|
|
|
|
|
(runtimeDiscordOps) => runtimeDiscordOps.listDirectoryGroupsLive,
|
|
|
|
|
);
|
|
|
|
|
const listDirectoryPeersLiveLazy = bindDiscordRuntimeMethod(
|
|
|
|
|
(runtimeDiscordOps) => runtimeDiscordOps.listDirectoryPeersLive,
|
|
|
|
|
);
|
|
|
|
|
const probeDiscordLazy = bindDiscordRuntimeMethod(
|
|
|
|
|
(runtimeDiscordOps) => runtimeDiscordOps.probeDiscord,
|
|
|
|
|
);
|
|
|
|
|
const resolveChannelAllowlistLazy = bindDiscordRuntimeMethod(
|
|
|
|
|
(runtimeDiscordOps) => runtimeDiscordOps.resolveChannelAllowlist,
|
|
|
|
|
);
|
|
|
|
|
const resolveUserAllowlistLazy = bindDiscordRuntimeMethod(
|
|
|
|
|
(runtimeDiscordOps) => runtimeDiscordOps.resolveUserAllowlist,
|
|
|
|
|
);
|
|
|
|
|
const sendComponentMessageLazy = bindDiscordRuntimeMethod(
|
|
|
|
|
(runtimeDiscordOps) => runtimeDiscordOps.sendComponentMessage,
|
|
|
|
|
);
|
|
|
|
|
const sendMessageDiscordLazy = bindDiscordRuntimeMethod(
|
|
|
|
|
(runtimeDiscordOps) => runtimeDiscordOps.sendMessageDiscord,
|
|
|
|
|
);
|
|
|
|
|
const sendPollDiscordLazy = bindDiscordRuntimeMethod(
|
|
|
|
|
(runtimeDiscordOps) => runtimeDiscordOps.sendPollDiscord,
|
|
|
|
|
);
|
|
|
|
|
const monitorDiscordProviderLazy = bindDiscordRuntimeMethod(
|
|
|
|
|
(runtimeDiscordOps) => runtimeDiscordOps.monitorDiscordProvider,
|
|
|
|
|
);
|
|
|
|
|
const sendTypingDiscordLazy = bindDiscordRuntimeMethod(
|
|
|
|
|
(runtimeDiscordOps) => runtimeDiscordOps.typing.pulse,
|
|
|
|
|
);
|
|
|
|
|
const editMessageDiscordLazy = bindDiscordRuntimeMethod(
|
|
|
|
|
(runtimeDiscordOps) => runtimeDiscordOps.conversationActions.editMessage,
|
|
|
|
|
);
|
|
|
|
|
const deleteMessageDiscordLazy = bindDiscordRuntimeMethod(
|
2026-03-17 00:58:46 -07:00
|
|
|
(runtimeDiscordOps) => runtimeDiscordOps.conversationActions.deleteMessage,
|
|
|
|
|
);
|
2026-03-17 08:37:02 -07:00
|
|
|
const pinMessageDiscordLazy = bindDiscordRuntimeMethod(
|
|
|
|
|
(runtimeDiscordOps) => runtimeDiscordOps.conversationActions.pinMessage,
|
|
|
|
|
);
|
|
|
|
|
const unpinMessageDiscordLazy = bindDiscordRuntimeMethod(
|
|
|
|
|
(runtimeDiscordOps) => runtimeDiscordOps.conversationActions.unpinMessage,
|
|
|
|
|
);
|
|
|
|
|
const createThreadDiscordLazy = bindDiscordRuntimeMethod(
|
|
|
|
|
(runtimeDiscordOps) => runtimeDiscordOps.conversationActions.createThread,
|
|
|
|
|
);
|
|
|
|
|
const editChannelDiscordLazy = bindDiscordRuntimeMethod(
|
|
|
|
|
(runtimeDiscordOps) => runtimeDiscordOps.conversationActions.editChannel,
|
|
|
|
|
);
|
2026-03-16 02:05:10 -07:00
|
|
|
|
2026-03-16 00:24:40 -07:00
|
|
|
export function createRuntimeDiscord(): PluginRuntimeChannel["discord"] {
|
|
|
|
|
return {
|
|
|
|
|
messageActions: discordMessageActions,
|
2026-03-16 02:05:10 -07:00
|
|
|
auditChannelPermissions: auditChannelPermissionsLazy,
|
|
|
|
|
listDirectoryGroupsLive: listDirectoryGroupsLiveLazy,
|
|
|
|
|
listDirectoryPeersLive: listDirectoryPeersLiveLazy,
|
|
|
|
|
probeDiscord: probeDiscordLazy,
|
|
|
|
|
resolveChannelAllowlist: resolveChannelAllowlistLazy,
|
|
|
|
|
resolveUserAllowlist: resolveUserAllowlistLazy,
|
|
|
|
|
sendComponentMessage: sendComponentMessageLazy,
|
|
|
|
|
sendMessageDiscord: sendMessageDiscordLazy,
|
|
|
|
|
sendPollDiscord: sendPollDiscordLazy,
|
|
|
|
|
monitorDiscordProvider: monitorDiscordProviderLazy,
|
2026-03-16 00:40:32 -07:00
|
|
|
threadBindings: {
|
|
|
|
|
getManager: getThreadBindingManager,
|
|
|
|
|
resolveIdleTimeoutMs: resolveThreadBindingIdleTimeoutMs,
|
|
|
|
|
resolveInactivityExpiresAt: resolveThreadBindingInactivityExpiresAt,
|
|
|
|
|
resolveMaxAgeMs: resolveThreadBindingMaxAgeMs,
|
|
|
|
|
resolveMaxAgeExpiresAt: resolveThreadBindingMaxAgeExpiresAt,
|
|
|
|
|
setIdleTimeoutBySessionKey: setThreadBindingIdleTimeoutBySessionKey,
|
|
|
|
|
setMaxAgeBySessionKey: setThreadBindingMaxAgeBySessionKey,
|
|
|
|
|
unbindBySessionKey: unbindThreadBindingsBySessionKey,
|
|
|
|
|
},
|
2026-03-16 00:24:40 -07:00
|
|
|
typing: {
|
2026-03-16 02:05:10 -07:00
|
|
|
pulse: sendTypingDiscordLazy,
|
2026-03-16 00:24:40 -07:00
|
|
|
start: async ({ channelId, accountId, cfg, intervalMs }) =>
|
|
|
|
|
await createDiscordTypingLease({
|
|
|
|
|
channelId,
|
|
|
|
|
accountId,
|
|
|
|
|
cfg,
|
|
|
|
|
intervalMs,
|
|
|
|
|
pulse: async ({ channelId, accountId, cfg }) =>
|
2026-03-16 02:05:10 -07:00
|
|
|
void (await sendTypingDiscordLazy(channelId, { accountId, cfg })),
|
2026-03-16 00:24:40 -07:00
|
|
|
}),
|
|
|
|
|
},
|
|
|
|
|
conversationActions: {
|
2026-03-16 02:05:10 -07:00
|
|
|
editMessage: editMessageDiscordLazy,
|
|
|
|
|
deleteMessage: deleteMessageDiscordLazy,
|
|
|
|
|
pinMessage: pinMessageDiscordLazy,
|
|
|
|
|
unpinMessage: unpinMessageDiscordLazy,
|
|
|
|
|
createThread: createThreadDiscordLazy,
|
|
|
|
|
editChannel: editChannelDiscordLazy,
|
2026-03-16 00:24:40 -07:00
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
}
|