refactor: unify typing callbacks
This commit is contained in:
@@ -12,6 +12,7 @@ import {
|
||||
removeAckReactionAfterReply,
|
||||
shouldAckReaction as shouldAckReactionGate,
|
||||
} from "../../channels/ack-reactions.js";
|
||||
import { createTypingCallbacks } from "../../channels/typing.js";
|
||||
import {
|
||||
formatInboundEnvelope,
|
||||
formatThreadStarterEnvelope,
|
||||
@@ -350,7 +351,12 @@ export async function processDiscordMessage(ctx: DiscordMessagePreflightContext)
|
||||
onError: (err, info) => {
|
||||
runtime.error?.(danger(`discord ${info.kind} reply failed: ${String(err)}`));
|
||||
},
|
||||
onReplyStart: () => sendTyping({ client, channelId: typingChannelId }),
|
||||
onReplyStart: createTypingCallbacks({
|
||||
start: () => sendTyping({ client, channelId: typingChannelId }),
|
||||
onStartError: (err) => {
|
||||
logVerbose(`discord typing cue failed for channel ${typingChannelId}: ${String(err)}`);
|
||||
},
|
||||
}).onReplyStart,
|
||||
});
|
||||
|
||||
const { queuedFinal, counts } = await dispatchInboundMessage({
|
||||
|
||||
@@ -1,15 +1,9 @@
|
||||
import type { Client } from "@buape/carbon";
|
||||
|
||||
import { logVerbose } from "../../globals.js";
|
||||
|
||||
export async function sendTyping(params: { client: Client; channelId: string }) {
|
||||
try {
|
||||
const channel = await params.client.fetchChannel(params.channelId);
|
||||
if (!channel) return;
|
||||
if ("triggerTyping" in channel && typeof channel.triggerTyping === "function") {
|
||||
await channel.triggerTyping();
|
||||
}
|
||||
} catch (err) {
|
||||
logVerbose(`discord typing cue failed for channel ${params.channelId}: ${String(err)}`);
|
||||
const channel = await params.client.fetchChannel(params.channelId);
|
||||
if (!channel) return;
|
||||
if ("triggerTyping" in channel && typeof channel.triggerTyping === "function") {
|
||||
await channel.triggerTyping();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user