style: auto-fix ESLint issues (curly braces and formatting)
- Add curly braces to all if/else/for/while statements - Fix indentation and trailing spaces - Auto-fixed 372 linting errors using eslint --fix - Remaining issues are warnings only (non-null assertions, explicit any types)
This commit is contained in:
@@ -14,7 +14,7 @@ function createMockClient() {
|
||||
_handlers: handlers,
|
||||
user: null as { id: string; tag: string } | null,
|
||||
on: vi.fn((event: string, handler: (...args: unknown[]) => void) => {
|
||||
if (!handlers.has(event)) handlers.set(event, []);
|
||||
if (!handlers.has(event)) {handlers.set(event, []);}
|
||||
handlers.get(event)!.push(handler);
|
||||
}),
|
||||
login: vi.fn(async (_token: string) => {
|
||||
@@ -23,7 +23,7 @@ function createMockClient() {
|
||||
// Trigger ready event asynchronously
|
||||
setTimeout(() => {
|
||||
const readyHandlers = handlers.get('ready') ?? [];
|
||||
for (const h of readyHandlers) h();
|
||||
for (const h of readyHandlers) {h();}
|
||||
}, 0);
|
||||
}),
|
||||
destroy: vi.fn(),
|
||||
|
||||
@@ -117,7 +117,7 @@ export class DiscordAdapter implements ChannelAdapter {
|
||||
|
||||
/** Send an outbound message, automatically chunking if it exceeds Discord's 2000-char limit. */
|
||||
async send(peerId: string, message: OutboundMessage): Promise<void> {
|
||||
if (!this.client) throw new Error('Discord adapter not connected');
|
||||
if (!this.client) {throw new Error('Discord adapter not connected');}
|
||||
|
||||
const channel = await this.client.channels.fetch(peerId);
|
||||
if (!channel || !('send' in channel)) {
|
||||
@@ -163,10 +163,10 @@ export class DiscordAdapter implements ChannelAdapter {
|
||||
|
||||
/** Internal: process an inbound Discord message. */
|
||||
private handleMessage(message: DiscordMessage): void {
|
||||
if (!this.messageHandler) return;
|
||||
if (!this.messageHandler) {return;}
|
||||
|
||||
// Ignore bot messages
|
||||
if (message.author.bot) return;
|
||||
if (message.author.bot) {return;}
|
||||
|
||||
const isDM = !message.guild;
|
||||
|
||||
|
||||
@@ -83,7 +83,7 @@ export class PairingManager {
|
||||
const normalizedCode = code.trim().toUpperCase();
|
||||
const pending = this.pendingCodes.get(normalizedCode);
|
||||
|
||||
if (!pending) return false;
|
||||
if (!pending) {return false;}
|
||||
if (Date.now() > pending.expiresAt) {
|
||||
this.pendingCodes.delete(normalizedCode);
|
||||
return false;
|
||||
|
||||
@@ -32,7 +32,7 @@ export class ChannelRegistry {
|
||||
/** Unregister an adapter by name. Calls disconnect() if connected. */
|
||||
async unregister(name: string): Promise<void> {
|
||||
const adapter = this.adapters.get(name);
|
||||
if (!adapter) return;
|
||||
if (!adapter) {return;}
|
||||
|
||||
if (adapter.status === 'connected' || adapter.status === 'connecting') {
|
||||
await adapter.disconnect();
|
||||
|
||||
@@ -50,7 +50,7 @@ const baseConfig: SlackAdapterConfig = {
|
||||
|
||||
/** Helper: simulate a Slack message event through the captured handler. */
|
||||
async function simulateMessage(message: Record<string, unknown>) {
|
||||
if (!capturedMessageHandler) throw new Error('No message handler captured — call connect() first');
|
||||
if (!capturedMessageHandler) {throw new Error('No message handler captured — call connect() first');}
|
||||
await capturedMessageHandler({ message });
|
||||
}
|
||||
|
||||
|
||||
@@ -128,15 +128,15 @@ export class SlackAdapter implements ChannelAdapter {
|
||||
|
||||
/** Send an outbound message, automatically chunking if it exceeds 4000 chars. */
|
||||
async send(peerId: string, message: OutboundMessage): Promise<void> {
|
||||
if (!this.app) throw new Error('Slack adapter not connected');
|
||||
if (!this.app) {throw new Error('Slack adapter not connected');}
|
||||
|
||||
// Parse peerId: "channelId:threadTs"
|
||||
const colonIndex = peerId.indexOf(':');
|
||||
if (colonIndex === -1) throw new Error(`Invalid peer ID format: ${peerId}`);
|
||||
if (colonIndex === -1) {throw new Error(`Invalid peer ID format: ${peerId}`);}
|
||||
|
||||
const channel = peerId.slice(0, colonIndex);
|
||||
const threadTs = peerId.slice(colonIndex + 1);
|
||||
if (!channel || !threadTs) throw new Error(`Invalid peer ID format: ${peerId}`);
|
||||
if (!channel || !threadTs) {throw new Error(`Invalid peer ID format: ${peerId}`);}
|
||||
|
||||
const text = message.text;
|
||||
|
||||
@@ -171,7 +171,7 @@ export class SlackAdapter implements ChannelAdapter {
|
||||
threadTs: string,
|
||||
attachment: OutboundAttachment,
|
||||
): Promise<void> {
|
||||
if (!this.app) return;
|
||||
if (!this.app) {return;}
|
||||
|
||||
try {
|
||||
if (attachment.data) {
|
||||
@@ -200,7 +200,7 @@ export class SlackAdapter implements ChannelAdapter {
|
||||
/** Resolve a Slack user ID to a display name, with caching. */
|
||||
private async resolveUserName(userId: string): Promise<string> {
|
||||
const cached = this.userNameCache.get(userId);
|
||||
if (cached) return cached;
|
||||
if (cached) {return cached;}
|
||||
|
||||
try {
|
||||
const result = await this.app!.client.users.info({ user: userId });
|
||||
@@ -219,16 +219,16 @@ export class SlackAdapter implements ChannelAdapter {
|
||||
private async extractMediaAttachments(
|
||||
files?: SlackMessageEvent['files'],
|
||||
): Promise<Attachment[]> {
|
||||
if (!files || files.length === 0) return [];
|
||||
if (!files || files.length === 0) {return [];}
|
||||
|
||||
const attachments: Attachment[] = [];
|
||||
|
||||
for (const file of files) {
|
||||
// Only process image and audio files
|
||||
if (!file.mimetype?.startsWith('image/') && !file.mimetype?.startsWith('audio/')) continue;
|
||||
if (!file.mimetype?.startsWith('image/') && !file.mimetype?.startsWith('audio/')) {continue;}
|
||||
|
||||
const downloadUrl = file.url_private_download || file.url_private;
|
||||
if (!downloadUrl) continue;
|
||||
if (!downloadUrl) {continue;}
|
||||
|
||||
try {
|
||||
const response = await fetch(downloadUrl, {
|
||||
@@ -264,13 +264,13 @@ export class SlackAdapter implements ChannelAdapter {
|
||||
|
||||
/** Internal: process an inbound Slack message event. */
|
||||
private async handleMessage(message: SlackMessageEvent): Promise<void> {
|
||||
if (!this.messageHandler) return;
|
||||
if (!this.messageHandler) {return;}
|
||||
|
||||
// Ignore bot messages
|
||||
if (message.bot_id || message.subtype === 'bot_message') return;
|
||||
if (message.bot_id || message.subtype === 'bot_message') {return;}
|
||||
|
||||
const channelId = message.channel;
|
||||
if (!channelId) return;
|
||||
if (!channelId) {return;}
|
||||
|
||||
// Check allowed channel IDs
|
||||
if (
|
||||
|
||||
@@ -53,13 +53,13 @@ export class TelegramAdapter implements ChannelAdapter {
|
||||
private async downloadFileToBase64(fileId: string): Promise<string | null> {
|
||||
try {
|
||||
const file = await this.bot?.api.getFile(fileId);
|
||||
if (!file || !file.file_path) return null;
|
||||
if (!file || !file.file_path) {return null;}
|
||||
|
||||
const token = this.config.botToken;
|
||||
const url = `https://api.telegram.org/file/bot${token}/${file.file_path}`;
|
||||
|
||||
const response = await fetch(url);
|
||||
if (!response.ok) return null;
|
||||
if (!response.ok) {return null;}
|
||||
|
||||
const buffer = Buffer.from(await response.arrayBuffer());
|
||||
return buffer.toString('base64');
|
||||
@@ -82,7 +82,7 @@ export class TelegramAdapter implements ChannelAdapter {
|
||||
// ── Auth middleware — reject messages from unknown chats (with pairing fallback) ──
|
||||
this.bot.use(async (ctx, next) => {
|
||||
const chatId = ctx.chat?.id;
|
||||
if (chatId === undefined) return;
|
||||
if (chatId === undefined) {return;}
|
||||
|
||||
// Allowlist check
|
||||
if (isAllowedChat(chatId, this.config.allowedChatIds)) {
|
||||
@@ -166,7 +166,7 @@ export class TelegramAdapter implements ChannelAdapter {
|
||||
// ── Text message handler ──
|
||||
|
||||
this.bot.on('message:text', async (ctx) => {
|
||||
if (!this.messageHandler) return;
|
||||
if (!this.messageHandler) {return;}
|
||||
|
||||
// Group chat mention gating
|
||||
const isGroup = ctx.chat.type === 'group' || ctx.chat.type === 'supergroup';
|
||||
@@ -212,10 +212,10 @@ export class TelegramAdapter implements ChannelAdapter {
|
||||
// ── Photo message handler ──
|
||||
|
||||
this.bot.on('message:photo', async (ctx) => {
|
||||
if (!this.messageHandler) return;
|
||||
if (!this.messageHandler) {return;}
|
||||
|
||||
const photo = ctx.message.photo;
|
||||
if (!photo || photo.length === 0) return;
|
||||
if (!photo || photo.length === 0) {return;}
|
||||
|
||||
const largestPhoto = photo[photo.length - 1];
|
||||
|
||||
@@ -250,13 +250,13 @@ export class TelegramAdapter implements ChannelAdapter {
|
||||
// ── Image document handler ──
|
||||
|
||||
this.bot.on('message:document', async (ctx) => {
|
||||
if (!this.messageHandler) return;
|
||||
if (!this.messageHandler) {return;}
|
||||
|
||||
const document = ctx.message.document;
|
||||
if (!document) return;
|
||||
if (!document) {return;}
|
||||
|
||||
const mimeType = document.mime_type ?? '';
|
||||
if (!mimeType.startsWith('image/')) return;
|
||||
if (!mimeType.startsWith('image/')) {return;}
|
||||
|
||||
await ctx.replyWithChatAction('typing');
|
||||
|
||||
@@ -290,10 +290,10 @@ export class TelegramAdapter implements ChannelAdapter {
|
||||
// ── Voice message handler ──
|
||||
|
||||
this.bot.on('message:voice', async (ctx) => {
|
||||
if (!this.messageHandler) return;
|
||||
if (!this.messageHandler) {return;}
|
||||
|
||||
const voice = ctx.message.voice;
|
||||
if (!voice) return;
|
||||
if (!voice) {return;}
|
||||
|
||||
await ctx.replyWithChatAction('typing');
|
||||
|
||||
@@ -327,10 +327,10 @@ export class TelegramAdapter implements ChannelAdapter {
|
||||
// ── Audio message handler ──
|
||||
|
||||
this.bot.on('message:audio', async (ctx) => {
|
||||
if (!this.messageHandler) return;
|
||||
if (!this.messageHandler) {return;}
|
||||
|
||||
const audio = ctx.message.audio;
|
||||
if (!audio) return;
|
||||
if (!audio) {return;}
|
||||
|
||||
await ctx.replyWithChatAction('typing');
|
||||
|
||||
@@ -388,7 +388,7 @@ export class TelegramAdapter implements ChannelAdapter {
|
||||
|
||||
/** Send an outbound message, automatically chunking if it exceeds Telegram's limit. */
|
||||
async send(peerId: string, message: OutboundMessage): Promise<void> {
|
||||
if (!this.bot) throw new Error('Telegram adapter not connected');
|
||||
if (!this.bot) {throw new Error('Telegram adapter not connected');}
|
||||
|
||||
const chatId = Number(peerId);
|
||||
const text = message.text;
|
||||
@@ -413,7 +413,7 @@ export class TelegramAdapter implements ChannelAdapter {
|
||||
|
||||
/** Send a single outbound attachment via the Telegram API. */
|
||||
private async sendAttachment(chatId: number, attachment: OutboundAttachment): Promise<void> {
|
||||
if (!this.bot) return;
|
||||
if (!this.bot) {return;}
|
||||
|
||||
try {
|
||||
const file = attachment.data
|
||||
|
||||
@@ -146,7 +146,7 @@ export class WhatsAppAdapter implements ChannelAdapter {
|
||||
|
||||
/** Send an outbound message, automatically chunking if it exceeds 4096 chars. */
|
||||
async send(peerId: string, message: OutboundMessage): Promise<void> {
|
||||
if (!this.client) throw new Error('WhatsApp adapter not connected');
|
||||
if (!this.client) {throw new Error('WhatsApp adapter not connected');}
|
||||
|
||||
const text = message.text;
|
||||
|
||||
@@ -169,7 +169,7 @@ export class WhatsAppAdapter implements ChannelAdapter {
|
||||
|
||||
/** Send a single outbound attachment via WhatsApp using MessageMedia. */
|
||||
private async sendAttachment(peerId: string, attachment: OutboundAttachment): Promise<void> {
|
||||
if (!this.client) return;
|
||||
if (!this.client) {return;}
|
||||
|
||||
try {
|
||||
if (attachment.data) {
|
||||
@@ -194,10 +194,10 @@ export class WhatsAppAdapter implements ChannelAdapter {
|
||||
|
||||
/** Internal: process an inbound WhatsApp message. */
|
||||
private async handleMessage(message: WhatsAppMessage): Promise<void> {
|
||||
if (!this.messageHandler) return;
|
||||
if (!this.messageHandler) {return;}
|
||||
|
||||
// Ignore messages from the bot itself
|
||||
if (message.fromMe) return;
|
||||
if (message.fromMe) {return;}
|
||||
|
||||
const from = message.from;
|
||||
|
||||
@@ -223,7 +223,7 @@ export class WhatsAppAdapter implements ChannelAdapter {
|
||||
? message.body?.includes(`@${this.botId.replace(/@c\.us$/, '')}`) ||
|
||||
(message as any).mentionedIds?.some((id: string) => id === this.botId)
|
||||
: false;
|
||||
if (!mentionsBot) return;
|
||||
if (!mentionsBot) {return;}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user