chore: migrate to oxlint and oxfmt
Co-authored-by: Christoph Nakazawa <christoph.pojer@gmail.com>
This commit is contained in:
@@ -1,8 +1,5 @@
|
||||
import { chunkText, resolveTextChunkLimit } from "../auto-reply/chunk.js";
|
||||
import {
|
||||
DEFAULT_GROUP_HISTORY_LIMIT,
|
||||
type HistoryEntry,
|
||||
} from "../auto-reply/reply/history.js";
|
||||
import { DEFAULT_GROUP_HISTORY_LIMIT, type HistoryEntry } from "../auto-reply/reply/history.js";
|
||||
import type { ReplyPayload } from "../auto-reply/types.js";
|
||||
import type { ClawdbotConfig } from "../config/config.js";
|
||||
import { loadConfig } from "../config/config.js";
|
||||
@@ -80,9 +77,7 @@ type SignalReactionTarget = {
|
||||
display: string;
|
||||
};
|
||||
|
||||
function resolveSignalReactionTargets(
|
||||
reaction: SignalReactionMessage,
|
||||
): SignalReactionTarget[] {
|
||||
function resolveSignalReactionTargets(reaction: SignalReactionMessage): SignalReactionTarget[] {
|
||||
const targets: SignalReactionTarget[] = [];
|
||||
const uuid = reaction.targetAuthorUuid?.trim();
|
||||
if (uuid) {
|
||||
@@ -102,12 +97,8 @@ function isSignalReactionMessage(
|
||||
if (!reaction) return false;
|
||||
const emoji = reaction.emoji?.trim();
|
||||
const timestamp = reaction.targetSentTimestamp;
|
||||
const hasTarget = Boolean(
|
||||
reaction.targetAuthor?.trim() || reaction.targetAuthorUuid?.trim(),
|
||||
);
|
||||
return Boolean(
|
||||
emoji && typeof timestamp === "number" && timestamp > 0 && hasTarget,
|
||||
);
|
||||
const hasTarget = Boolean(reaction.targetAuthor?.trim() || reaction.targetAuthorUuid?.trim());
|
||||
return Boolean(emoji && typeof timestamp === "number" && timestamp > 0 && hasTarget);
|
||||
}
|
||||
|
||||
function shouldEmitSignalReactionNotification(params: {
|
||||
@@ -146,12 +137,8 @@ function buildSignalReactionSystemEventText(params: {
|
||||
groupLabel?: string;
|
||||
}) {
|
||||
const base = `Signal reaction added: ${params.emojiLabel} by ${params.actorLabel} msg ${params.messageId}`;
|
||||
const withTarget = params.targetLabel
|
||||
? `${base} from ${params.targetLabel}`
|
||||
: base;
|
||||
return params.groupLabel
|
||||
? `${withTarget} in ${params.groupLabel}`
|
||||
: withTarget;
|
||||
const withTarget = params.targetLabel ? `${base} from ${params.targetLabel}` : base;
|
||||
return params.groupLabel ? `${withTarget} in ${params.groupLabel}` : withTarget;
|
||||
}
|
||||
|
||||
async function waitForSignalDaemonReady(params: {
|
||||
@@ -167,15 +154,12 @@ async function waitForSignalDaemonReady(params: {
|
||||
if (params.abortSignal?.aborted) return;
|
||||
const res = await signalCheck(params.baseUrl, 1000);
|
||||
if (res.ok) return;
|
||||
lastError =
|
||||
res.error ?? (res.status ? `HTTP ${res.status}` : "unreachable");
|
||||
lastError = res.error ?? (res.status ? `HTTP ${res.status}` : "unreachable");
|
||||
await new Promise((r) => setTimeout(r, 150));
|
||||
}
|
||||
|
||||
params.runtime.error?.(
|
||||
danger(
|
||||
`daemon not ready after ${params.timeoutMs}ms (${lastError ?? "unknown error"})`,
|
||||
),
|
||||
danger(`daemon not ready after ${params.timeoutMs}ms (${lastError ?? "unknown error"})`),
|
||||
);
|
||||
throw new Error(`signal daemon not ready (${lastError ?? "unknown error"})`);
|
||||
}
|
||||
@@ -203,11 +187,9 @@ async function fetchAttachment(params: {
|
||||
else if (params.sender) rpcParams.recipient = params.sender;
|
||||
else return null;
|
||||
|
||||
const result = await signalRpcRequest<{ data?: string }>(
|
||||
"getAttachment",
|
||||
rpcParams,
|
||||
{ baseUrl: params.baseUrl },
|
||||
);
|
||||
const result = await signalRpcRequest<{ data?: string }>("getAttachment", rpcParams, {
|
||||
baseUrl: params.baseUrl,
|
||||
});
|
||||
if (!result?.data) return null;
|
||||
const buffer = Buffer.from(result.data, "base64");
|
||||
const saved = await saveMediaBuffer(
|
||||
@@ -229,19 +211,9 @@ async function deliverReplies(params: {
|
||||
maxBytes: number;
|
||||
textLimit: number;
|
||||
}) {
|
||||
const {
|
||||
replies,
|
||||
target,
|
||||
baseUrl,
|
||||
account,
|
||||
accountId,
|
||||
runtime,
|
||||
maxBytes,
|
||||
textLimit,
|
||||
} = params;
|
||||
const { replies, target, baseUrl, account, accountId, runtime, maxBytes, textLimit } = params;
|
||||
for (const payload of replies) {
|
||||
const mediaList =
|
||||
payload.mediaUrls ?? (payload.mediaUrl ? [payload.mediaUrl] : []);
|
||||
const mediaList = payload.mediaUrls ?? (payload.mediaUrl ? [payload.mediaUrl] : []);
|
||||
const text = payload.text ?? "";
|
||||
if (!text && mediaList.length === 0) continue;
|
||||
if (mediaList.length === 0) {
|
||||
@@ -271,9 +243,7 @@ async function deliverReplies(params: {
|
||||
}
|
||||
}
|
||||
|
||||
export async function monitorSignalProvider(
|
||||
opts: MonitorSignalOpts = {},
|
||||
): Promise<void> {
|
||||
export async function monitorSignalProvider(opts: MonitorSignalOpts = {}): Promise<void> {
|
||||
const runtime = resolveRuntime(opts);
|
||||
const cfg = opts.config ?? loadConfig();
|
||||
const accountInfo = resolveSignalAccount({
|
||||
@@ -291,9 +261,7 @@ export async function monitorSignalProvider(
|
||||
const baseUrl = opts.baseUrl?.trim() || accountInfo.baseUrl;
|
||||
const account = opts.account?.trim() || accountInfo.config.account?.trim();
|
||||
const dmPolicy = accountInfo.config.dmPolicy ?? "pairing";
|
||||
const allowFrom = normalizeAllowList(
|
||||
opts.allowFrom ?? accountInfo.config.allowFrom,
|
||||
);
|
||||
const allowFrom = normalizeAllowList(opts.allowFrom ?? accountInfo.config.allowFrom);
|
||||
const groupAllowFrom = normalizeAllowList(
|
||||
opts.groupAllowFrom ??
|
||||
accountInfo.config.groupAllowFrom ??
|
||||
@@ -303,24 +271,16 @@ export async function monitorSignalProvider(
|
||||
);
|
||||
const groupPolicy = accountInfo.config.groupPolicy ?? "allowlist";
|
||||
const reactionMode = accountInfo.config.reactionNotifications ?? "own";
|
||||
const reactionAllowlist = normalizeAllowList(
|
||||
accountInfo.config.reactionAllowlist,
|
||||
);
|
||||
const mediaMaxBytes =
|
||||
(opts.mediaMaxMb ?? accountInfo.config.mediaMaxMb ?? 8) * 1024 * 1024;
|
||||
const ignoreAttachments =
|
||||
opts.ignoreAttachments ?? accountInfo.config.ignoreAttachments ?? false;
|
||||
const reactionAllowlist = normalizeAllowList(accountInfo.config.reactionAllowlist);
|
||||
const mediaMaxBytes = (opts.mediaMaxMb ?? accountInfo.config.mediaMaxMb ?? 8) * 1024 * 1024;
|
||||
const ignoreAttachments = opts.ignoreAttachments ?? accountInfo.config.ignoreAttachments ?? false;
|
||||
|
||||
const autoStart =
|
||||
opts.autoStart ??
|
||||
accountInfo.config.autoStart ??
|
||||
!accountInfo.config.httpUrl;
|
||||
const autoStart = opts.autoStart ?? accountInfo.config.autoStart ?? !accountInfo.config.httpUrl;
|
||||
let daemonHandle: ReturnType<typeof spawnSignalDaemon> | null = null;
|
||||
|
||||
if (autoStart) {
|
||||
const cliPath = opts.cliPath ?? accountInfo.config.cliPath ?? "signal-cli";
|
||||
const httpHost =
|
||||
opts.httpHost ?? accountInfo.config.httpHost ?? "127.0.0.1";
|
||||
const httpHost = opts.httpHost ?? accountInfo.config.httpHost ?? "127.0.0.1";
|
||||
const httpPort = opts.httpPort ?? accountInfo.config.httpPort ?? 8080;
|
||||
daemonHandle = spawnSignalDaemon({
|
||||
cliPath,
|
||||
@@ -328,11 +288,9 @@ export async function monitorSignalProvider(
|
||||
httpHost,
|
||||
httpPort,
|
||||
receiveMode: opts.receiveMode ?? accountInfo.config.receiveMode,
|
||||
ignoreAttachments:
|
||||
opts.ignoreAttachments ?? accountInfo.config.ignoreAttachments,
|
||||
ignoreAttachments: opts.ignoreAttachments ?? accountInfo.config.ignoreAttachments,
|
||||
ignoreStories: opts.ignoreStories ?? accountInfo.config.ignoreStories,
|
||||
sendReadReceipts:
|
||||
opts.sendReadReceipts ?? accountInfo.config.sendReadReceipts,
|
||||
sendReadReceipts: opts.sendReadReceipts ?? accountInfo.config.sendReadReceipts,
|
||||
runtime,
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user