diff --git a/.prettierrc b/.prettierrc deleted file mode 100644 index 2fc2fbf..0000000 --- a/.prettierrc +++ /dev/null @@ -1,12 +0,0 @@ -{ - "useTabs": true, - "printWidth": 80, - "endOfLine": "lf", - "arrowParens": "avoid", - "embeddedLanguageFormatting": "auto", - "proseWrap": "always", - "quoteProps": "as-needed", - "semi": true, - "singleQuote": true, - "trailingComma": "none" -} diff --git a/deno.jsonc b/deno.jsonc new file mode 100644 index 0000000..141656a --- /dev/null +++ b/deno.jsonc @@ -0,0 +1,22 @@ +{ + "fmt": { + "lineWidth": 80, + "proseWrap": "always", + "semiColons": true, + "useTabs": true, + "singleQuote": true + }, + "lint": { + "rules": { + "include": [ + "ban-untagged-todo", + "default-param-last", + "eqeqeq", + "no-eval", + "no-external-import", + "triple-slash-reference", + "verbatim-module-syntax" + ] + } + } +} diff --git a/packages/bolt-discord/conv.ts b/packages/bolt-discord/conv.ts index 78cc3b9..8c0af7d 100644 --- a/packages/bolt-discord/conv.ts +++ b/packages/bolt-discord/conv.ts @@ -1,13 +1,13 @@ import type { API, APIInteraction, - RawFile, command, command_arguments, message, + RawFile, update_data, wh_query, - wh_token + wh_token, } from './deps.ts'; async function async_flat(arr: A[], f: (a: A) => Promise) { @@ -16,7 +16,7 @@ async function async_flat(arr: A[], f: (a: A) => Promise) { function to_instant(id: string) { return Temporal.Instant.fromEpochMilliseconds( - Number(BigInt(id) >> 22n) + 1420070400000 + Number(BigInt(id) >> 22n) + 1420070400000, ); } @@ -26,7 +26,7 @@ type webhook_message = wh_query & wh_token & { files?: RawFile[]; wait: true }; export async function to_discord( message: message, - replied_message?: discord_message + replied_message?: discord_message, ): Promise { if (message.reply_id && replied_message) { if (!message.embeds) message.embeds = []; @@ -39,48 +39,49 @@ export async function to_discord( replied_message.author?.username || 'a user' }`, - icon_url: `https://cdn.discordapp.com/avatars/${replied_message.author?.id}/${replied_message.author?.avatar}.png` + icon_url: + `https://cdn.discordapp.com/avatars/${replied_message.author?.id}/${replied_message.author?.avatar}.png`, }, - description: replied_message.content + description: replied_message.content, }, - ...(replied_message.embeds || []).map(i => { + ...(replied_message.embeds || []).map((i) => { return { ...i, timestamp: i.timestamp ? Number(i.timestamp) : undefined, - video: i.video ? { ...i.video, url: i.video.url || '' } : undefined + video: i.video ? { ...i.video, url: i.video.url || '' } : undefined, }; - }) + }), ); } return { avatar_url: message.author.profile, content: message.content, - embeds: message.embeds?.map(i => { + embeds: message.embeds?.map((i) => { return { ...i, - timestamp: i.timestamp ? String(i.timestamp) : undefined + timestamp: i.timestamp ? String(i.timestamp) : undefined, }; }), files: message.attachments - ? await async_flat(message.attachments, async a => { - if (a.size > 25) return []; - if (!a.name) a.name = a.file.split('/').pop(); - return [ - { - name: a.name || 'file', - data: new Uint8Array(await (await fetch(a.file)).arrayBuffer()) - } - ]; - }) + ? await async_flat(message.attachments, async (a) => { + if (a.size > 25) return []; + if (!a.name) a.name = a.file.split('/').pop(); + return [ + { + name: a.name || 'file', + data: new Uint8Array(await (await fetch(a.file)).arrayBuffer()), + }, + ]; + }) : undefined, username: message.author.username, - wait: true + wait: true, }; } export async function to_core( api: API, - message: discord_message + message: discord_message, ): Promise { if (message.flags && message.flags & 128) message.content = 'Loading...'; if (message.type === 7) message.content = '*joined on discord*'; @@ -101,7 +102,7 @@ export async function to_core( filename: `${sticker.name}.${type}`, size: 0, id: sticker.id, - proxy_url: url + proxy_url: url, }); } else { message.content = '*used sticker*'; @@ -110,48 +111,47 @@ export async function to_core( } const data = { author: { - profile: `https://cdn.discordapp.com/avatars/${message.author?.id}/${message.author?.avatar}.png`, - username: - message.member?.nick || + profile: + `https://cdn.discordapp.com/avatars/${message.author?.id}/${message.author?.avatar}.png`, + username: message.member?.nick || message.author?.global_name || message.author?.username || 'discord user', rawname: message.author?.username || 'discord user', id: message.author?.id || message.webhook_id || '', - color: '#5865F2' + color: '#5865F2', }, channel: message.channel_id, - content: - (message.content?.length || 0) > 2000 - ? `${message.content?.substring(0, 1997)}...` - : message.content, + content: (message.content?.length || 0) > 2000 + ? `${message.content?.substring(0, 1997)}...` + : message.content, id: message.id, timestamp: to_instant(message.id), - embeds: message.embeds?.map(i => { + embeds: message.embeds?.map((i) => { return { ...i, - timestamp: i.timestamp ? Number(i.timestamp) : undefined + timestamp: i.timestamp ? Number(i.timestamp) : undefined, }; }), reply: async (msg: message) => { - if (!data.author.id || data.author.id == '') return; + if (!data.author.id || data.author.id === '') return; await api.channels.createMessage(message.channel_id, { ...(await to_discord(msg)), message_reference: { - message_id: message.id - } + message_id: message.id, + }, }); }, plugin: 'bolt-discord', - attachments: message.attachments?.map(i => { + attachments: message.attachments?.map((i) => { return { file: i.url, alt: i.description, name: i.filename, - size: i.size / 1000000 + size: i.size / 1000000, }; }), - reply_id: message.referenced_message?.id + reply_id: message.referenced_message?.id, }; return data as message; } @@ -169,17 +169,17 @@ export function to_command(interaction: { api: API; data: APIInteraction }) { return { cmd: interaction.data.data.name, subcmd, - reply: async msg => { + reply: async (msg) => { await interaction.api.interactions.reply( interaction.data.id, interaction.data.token, - await to_discord(msg) + await to_discord(msg), ); }, channel: interaction.data.channel.id, plugin: 'bolt-discord', opts, - timestamp: to_instant(interaction.data.id) + timestamp: to_instant(interaction.data.id), } as command_arguments; } @@ -191,29 +191,29 @@ export function to_intent_opts({ options }: command) { name: options.argument_name, description: 'option to pass to this command', type: 3, - required: options.argument_required + required: options.argument_required, }); } if (options?.subcommands) { opts.push( - ...options.subcommands.map(i => { + ...options.subcommands.map((i) => { return { name: i.name, description: i.description || i.name, type: 1, options: i.options?.argument_name ? [ - { - name: i.options.argument_name, - description: i.options.argument_name, - type: 3, - required: i.options.argument_required || false - } - ] - : undefined + { + name: i.options.argument_name, + description: i.options.argument_name, + type: 3, + required: i.options.argument_required || false, + }, + ] + : undefined, }; - }) + }), ); } diff --git a/packages/bolt-discord/deps.ts b/packages/bolt-discord/deps.ts index 654fa27..b4d8954 100644 --- a/packages/bolt-discord/deps.ts +++ b/packages/bolt-discord/deps.ts @@ -1,21 +1,20 @@ export { - Client, - GatewayDispatchEvents, type API, type APIInteraction, + Client, + GatewayDispatchEvents, type GatewayMessageUpdateDispatchData as update_data, + type RESTPostAPIWebhookWithTokenJSONBody as wh_token, type RESTPostAPIWebhookWithTokenQuery as wh_query, - type RESTPostAPIWebhookWithTokenJSONBody as wh_token } from 'npm:@discordjs/core@1.2.0'; -export { REST, type RawFile } from 'npm:@discordjs/rest@2.3.0'; +export { type RawFile, REST } from 'npm:@discordjs/rest@2.3.0'; export { WebSocketManager } from 'npm:@discordjs/ws@1.1.0'; export { - plugin, type bridge_channel, type command, type command_arguments, type deleted_message, type lightning, - type message + type message, + plugin, } from '../lightning/mod.ts'; - diff --git a/packages/bolt-discord/mod.ts b/packages/bolt-discord/mod.ts index 7230612..41b09c2 100644 --- a/packages/bolt-discord/mod.ts +++ b/packages/bolt-discord/mod.ts @@ -3,9 +3,9 @@ import type { deleted_message, lightning, message } from './deps.ts'; import { Client, GatewayDispatchEvents, + plugin, REST, WebSocketManager, - plugin } from './deps.ts'; import * as to from './to.ts'; @@ -32,13 +32,13 @@ export class discord_plugin extends plugin { const rest = new REST({ version: '10', /* @ts-ignore this works */ - makeRequest: fetch + makeRequest: fetch, }).setToken(this.config.token); const gateway = new WebSocketManager({ rest, token: this.config.token, - intents: 0 | 33281 + intents: 0 | 33281, }); gateway.connect(); @@ -47,21 +47,21 @@ export class discord_plugin extends plugin { } private setup_events() { - this.bot.on(GatewayDispatchEvents.MessageCreate, async msg => { + this.bot.on(GatewayDispatchEvents.MessageCreate, async (msg) => { this.emit('create_message', await conv.to_core(msg.api, msg.data)); }); - this.bot.on(GatewayDispatchEvents.MessageUpdate, async msg => { + this.bot.on(GatewayDispatchEvents.MessageUpdate, async (msg) => { this.emit('edit_message', await conv.to_core(msg.api, msg.data)); }); - this.bot.on(GatewayDispatchEvents.MessageDelete, async msg => { + this.bot.on(GatewayDispatchEvents.MessageDelete, async (msg) => { this.emit('delete_message', await conv.to_core(msg.api, msg.data)); }); - this.bot.on(GatewayDispatchEvents.InteractionCreate, interaction => { + this.bot.on(GatewayDispatchEvents.InteractionCreate, (interaction) => { const cmd = conv.to_command(interaction); - if (cmd) this.emit("run_command", cmd); + if (cmd) this.emit('run_command', cmd); }); } @@ -70,14 +70,14 @@ export class discord_plugin extends plugin { this.bot.api.applicationCommands.bulkOverwriteGlobalCommands( this.config.app_id, - [...this.lightning.commands.values()].map(command => { + [...this.lightning.commands.values()].map((command) => { return { name: command.name, type: 1, description: command.description || 'a command', - options: conv.to_intent_opts(command) + options: conv.to_intent_opts(command), }; - }) + }), ); } @@ -89,7 +89,7 @@ export class discord_plugin extends plugin { msg: message, bridge: to.channel, _?: undefined, - reply_id?: string + reply_id?: string, ): Promise { return to.send_to_discord(this.bot.api, msg, bridge, _, reply_id); } @@ -98,7 +98,7 @@ export class discord_plugin extends plugin { msg: message, bridge: to.channel, edit_id: string, - reply_id?: string + reply_id?: string, ): Promise { return to.send_to_discord(this.bot.api, msg, bridge, edit_id, reply_id); } diff --git a/packages/bolt-discord/to.ts b/packages/bolt-discord/to.ts index 3627d33..da49ebc 100644 --- a/packages/bolt-discord/to.ts +++ b/packages/bolt-discord/to.ts @@ -7,7 +7,7 @@ export type channel = bridge_channel & { export async function webhook_on_discord(api: API, channel: string) { const { id, token } = await api.channels.createWebhook(channel, { - name: 'bolt bridge' + name: 'lightning bridge', }); return { id, token }; @@ -18,7 +18,7 @@ export async function send_to_discord( message: message, channel: channel, edit_id?: string, - reply_id?: string + reply_id?: string, ) { let replied_message; @@ -40,7 +40,7 @@ export async function send_to_discord( channel.data.id, channel.data.token, edit_id, - msg + msg, ); } else { wh = await api.webhooks.execute(channel.data.id, channel.data.token, msg); @@ -59,7 +59,7 @@ export async function send_to_discord( export async function delete_on_discord( api: API, channel: channel, - id: string + id: string, ) { try { await api.webhooks.deleteMessage(channel.data.id, channel.data.token, id); diff --git a/packages/bolt-guilded/deps.ts b/packages/bolt-guilded/deps.ts index 9b178a7..af0af3e 100644 --- a/packages/bolt-guilded/deps.ts +++ b/packages/bolt-guilded/deps.ts @@ -1,17 +1,16 @@ export { Client, - WebhookClient, type EmbedPayload, type Message, type RESTPostWebhookBody, - type WebhookPayload + WebhookClient, + type WebhookPayload, } from 'npm:guilded.js@0.24.2'; export { - plugin, type bridge_channel, type deleted_message, type embed, type lightning, - type message + type message, + plugin, } from '../lightning/mod.ts'; - diff --git a/packages/bolt-guilded/guilded.ts b/packages/bolt-guilded/guilded.ts index 45e9776..3d6f1ad 100644 --- a/packages/bolt-guilded/guilded.ts +++ b/packages/bolt-guilded/guilded.ts @@ -1,30 +1,33 @@ import type { Client, + embed, EmbedPayload, + message, RESTPostWebhookBody, - embed, - message } from './deps.ts'; -import { guilded_plugin } from './mod.ts'; +import type { guilded_plugin } from './mod.ts'; export async function create_webhook( bot: Client, channel: string, - token: string + token: string, ) { const ch = await bot.channels.fetch(channel); - const resp = await fetch(`https://www.guilded.gg/api/v1/servers/${ch.serverId}/webhooks`, { - body: `{"name":"Lightning Bridges","channelId":"${channel}"}`, - headers: { - Accept: 'application/json', - Authorization: `Bearer ${token}`, - 'Content-Type': 'application/json' + const resp = await fetch( + `https://www.guilded.gg/api/v1/servers/${ch.serverId}/webhooks`, + { + body: `{"name":"Lightning Bridges","channelId":"${channel}"}`, + headers: { + Accept: 'application/json', + Authorization: `Bearer ${token}`, + 'Content-Type': 'application/json', + }, + method: 'POST', }, - method: 'POST' - }); + ); if (!resp.ok) { throw new Error('Webhook creation failed!', { - cause: await resp.text() + cause: await resp.text(), }); } const wh = await resp.json(); @@ -36,7 +39,7 @@ type guilded_msg = RESTPostWebhookBody & { replyMessageIds?: string[] }; export async function convert_msg( msg: message, channel?: string, - plugin?: guilded_plugin + plugin?: guilded_plugin, ): Promise { const message = { content: msg.content, @@ -44,8 +47,8 @@ export async function convert_msg( username: get_valid_username(msg), embeds: [ ...fix_embed(msg.embeds), - ...(await get_reply_embeds(msg, channel, plugin)) - ] + ...(await get_reply_embeds(msg, channel, plugin)), + ], } as guilded_msg; if (msg.reply_id) message.replyMessageIds = [msg.reply_id]; @@ -56,14 +59,14 @@ export async function convert_msg( title: 'attachments', description: msg.attachments .slice(0, 5) - .map(a => { + .map((a) => { return `![${a.alt || a.name}](${a.file})`; }) - .join('\n') + .join('\n'), }); } - if (message.embeds?.length == 0 || !message.embeds) delete message.embeds; + if (message.embeds?.length === 0 || !message.embeds) delete message.embeds; return message; } @@ -86,30 +89,30 @@ function get_valid_username(msg: message) { async function get_reply_embeds( msg: message, channel?: string, - plugin?: guilded_plugin + plugin?: guilded_plugin, ) { if (!msg.reply_id || !channel || !plugin) return []; try { const msg_replied_to = await plugin.bot.messages.fetch( channel, - msg.reply_id + msg.reply_id, ); let author; if (!msg_replied_to.createdByWebhookId) { author = await plugin.bot.members.fetch( msg_replied_to.serverId!, - msg_replied_to.authorId + msg_replied_to.authorId, ); } return [ { author: { name: `reply to ${author?.nickname || author?.username || 'a user'}`, - icon_url: author?.user?.avatar || undefined + icon_url: author?.user?.avatar || undefined, }, - description: msg_replied_to.content + description: msg_replied_to.content, }, - ...(msg_replied_to.embeds || []) + ...(msg_replied_to.embeds || []), ] as EmbedPayload[]; } catch { return []; @@ -117,18 +120,18 @@ async function get_reply_embeds( } function fix_embed(embeds: embed[] = []) { - return embeds.flatMap(embed => { - Object.keys(embed).forEach(key => { + return embeds.flatMap((embed) => { + Object.keys(embed).forEach((key) => { embed[key as keyof embed] === null ? (embed[key as keyof embed] = undefined) : embed[key as keyof embed]; }); - if (!embed.description || embed.description == '') return []; + if (!embed.description || embed.description === '') return []; return [ { ...embed, - timestamp: embed.timestamp ? String(embed.timestamp) : undefined - } + timestamp: embed.timestamp ? String(embed.timestamp) : undefined, + }, ]; }) as (EmbedPayload & { timestamp: string })[]; } diff --git a/packages/bolt-guilded/messages.ts b/packages/bolt-guilded/messages.ts index 4aa3d5b..7d299e2 100644 --- a/packages/bolt-guilded/messages.ts +++ b/packages/bolt-guilded/messages.ts @@ -1,10 +1,10 @@ -import { Message, message } from './deps.ts'; +import type { Message, message } from './deps.ts'; import { convert_msg } from './guilded.ts'; -import { guilded_plugin } from './mod.ts'; +import type { guilded_plugin } from './mod.ts'; export async function tocore( message: Message, - plugin: guilded_plugin + plugin: guilded_plugin, ): Promise { if (!message.serverId) return; let author; @@ -18,38 +18,38 @@ export async function tocore( rawname: author?.username || 'user on guilded', profile: author?.user?.avatar || undefined, id: message.authorId, - color: '#F5C400' + color: '#F5C400', }, channel: message.channelId, id: message.id, timestamp: Temporal.Instant.fromEpochMilliseconds( - message.createdAt.valueOf() + message.createdAt.valueOf(), ), - embeds: message.embeds?.map(embed => { + embeds: message.embeds?.map((embed) => { return { ...embed, author: embed.author ? { - name: embed.author.name || 'embed author', - iconUrl: embed.author.iconURL || undefined, - url: embed.author.url || undefined - } + name: embed.author.name || 'embed author', + iconUrl: embed.author.iconURL || undefined, + url: embed.author.url || undefined, + } : undefined, image: embed.image || undefined, thumbnail: embed.thumbnail || undefined, timestamp: embed.timestamp ? Number(embed.timestamp) : undefined, color: embed.color || undefined, description: embed.description || undefined, - fields: embed.fields.map(i => { + fields: embed.fields.map((i) => { return { ...i, - inline: i.inline || undefined + inline: i.inline || undefined, }; }), footer: embed.footer || undefined, title: embed.title || undefined, url: embed.url || undefined, - video: embed.video || undefined + video: embed.video || undefined, }; }), plugin: 'bolt-guilded', @@ -57,6 +57,6 @@ export async function tocore( await message.reply(await convert_msg(msg)); }, content: update_content, - reply_id: message.isReply ? message.replyMessageIds[0] : undefined + reply_id: message.isReply ? message.replyMessageIds[0] : undefined, }; } diff --git a/packages/bolt-guilded/mod.ts b/packages/bolt-guilded/mod.ts index cfdecb2..6f5e6ec 100644 --- a/packages/bolt-guilded/mod.ts +++ b/packages/bolt-guilded/mod.ts @@ -2,9 +2,9 @@ import type { bridge_channel, deleted_message, lightning, - message + message, } from './deps.ts'; -import { Client, WebhookClient, plugin } from './deps.ts'; +import { Client, plugin, WebhookClient } from './deps.ts'; import { convert_msg, create_webhook } from './guilded.ts'; import { tocore } from './messages.ts'; @@ -17,8 +17,8 @@ export class guilded_plugin extends plugin<{ token: string }> { super(l, c); const h = { headers: { - 'x-guilded-bot-api-use-official-markdown': 'true' - } + 'x-guilded-bot-api-use-official-markdown': 'true', + }, }; this.bot = new Client({ token: c.token, rest: h, ws: h }); this.setup_events(); @@ -26,20 +26,20 @@ export class guilded_plugin extends plugin<{ token: string }> { } private setup_events() { - this.bot.on('messageCreated', async message => { + this.bot.on('messageCreated', async (message) => { const msg = await tocore(message, this); if (msg) this.emit('create_message', msg); }); - this.bot.on('messageUpdated', async message => { + this.bot.on('messageUpdated', async (message) => { const msg = await tocore(message, this); if (msg) this.emit('edit_message', msg); }); - this.bot.on('messageDeleted', del => { + this.bot.on('messageDeleted', (del) => { this.emit('delete_message', { channel: del.channelId, id: del.id, plugin: 'bolt-guilded', - timestamp: Temporal.Instant.from(del.deletedAt) + timestamp: Temporal.Instant.from(del.deletedAt), }); }); this.bot.ws.emitter.on('exit', () => { @@ -55,10 +55,10 @@ export class guilded_plugin extends plugin<{ token: string }> { message: message, channel: bridge_channel, _?: undefined, - reply_id?: string + reply_id?: string, ) { const { id } = await new WebhookClient( - channel.data as { token: string; id: string } + channel.data as { token: string; id: string }, ).send(await convert_msg({ ...message, reply_id }, channel.id, this)); return id; } @@ -71,7 +71,7 @@ export class guilded_plugin extends plugin<{ token: string }> { async delete_message( _message: deleted_message, channel: bridge_channel, - id: string + id: string, ) { const msg = await this.bot.messages.fetch(channel.id, id); await msg.delete(); diff --git a/packages/bolt-matrix/deps.ts b/packages/bolt-matrix/deps.ts index 4352d78..39c0190 100644 --- a/packages/bolt-matrix/deps.ts +++ b/packages/bolt-matrix/deps.ts @@ -6,12 +6,11 @@ export { Intent, MatrixUser, Request, - type WeakEvent + type WeakEvent, } from 'npm:matrix-appservice-bridge@10.1.0'; export { - plugin, type bridge_channel, type lightning, - type message + type message, + plugin, } from '../lightning/mod.ts'; - diff --git a/packages/bolt-matrix/events.ts b/packages/bolt-matrix/events.ts index dda8d76..5b5c44e 100644 --- a/packages/bolt-matrix/events.ts +++ b/packages/bolt-matrix/events.ts @@ -1,9 +1,9 @@ -import { Intent, message, Request, WeakEvent } from './deps.ts'; -import { matrix_plugin } from './mod.ts'; +import type { Intent, message, Request, WeakEvent } from './deps.ts'; +import type { matrix_plugin } from './mod.ts'; export async function onEvent( this: matrix_plugin, - request: Request + request: Request, ) { const event = request.getData(); const bot = this.bot.getBot(); @@ -22,13 +22,13 @@ export async function onEvent( if (event.type === 'm.room.message' && !event.content['m.new_content']) { this.emit( 'create_message', - await messageToCore(event, intent, this.config.homeserverUrl) + await messageToCore(event, intent, this.config.homeserverUrl), ); } if (event.type === 'm.room.message' && event.content['m.new_content']) { this.emit( 'edit_message', - await messageToCore(event, intent, this.config.homeserverUrl) + await messageToCore(event, intent, this.config.homeserverUrl), ); } if (event.type === 'm.room.redaction') { @@ -36,7 +36,7 @@ export async function onEvent( id: event.redacts as string, plugin: 'bolt-matrix', channel: event.room_id, - timestamp: Temporal.Instant.fromEpochMilliseconds(event.origin_server_ts) + timestamp: Temporal.Instant.fromEpochMilliseconds(event.origin_server_ts), }); } } @@ -44,14 +44,12 @@ export async function onEvent( export async function messageToCore( event: WeakEvent, intent: Intent, - homeserverUrl: string + homeserverUrl: string, ): Promise { console.log(event.content.formatted_body); const sender = await intent.getProfileInfo(event.sender); const is_reply = event.content['m.relates_to'] - ? event.content['m.relates_to']['m.in_reply_to'] != undefined - ? true - : false + ? event.content['m.relates_to']['m.in_reply_to'] !== undefined ? true : false : false; return { author: { @@ -59,32 +57,33 @@ export async function messageToCore( rawname: event.sender, id: event.sender, profile: sender.avatar_url - ? `${sender.avatar_url?.replace( + ? `${ + sender.avatar_url?.replace( 'mxc://', - `${homeserverUrl}/_matrix/media/v3/thumbnail/` - )}?width=96&height=96&method=scale` - : undefined + `${homeserverUrl}/_matrix/media/v3/thumbnail/`, + ) + }?width=96&height=96&method=scale` + : undefined, }, channel: event.room_id, - id: - event.content['m.relates_to']?.rel_type == 'm.replace' - ? event.content['m.relates_to'].event_id - : event.event_id, + id: event.content['m.relates_to']?.rel_type === 'm.replace' + ? event.content['m.relates_to'].event_id + : event.event_id, timestamp: Temporal.Instant.fromEpochMilliseconds(event.origin_server_ts), content: is_reply ? (event.content.formatted_body as string).replace( - /(.*?)<\/mx-reply>/i, - '' - ) + /(.*?)<\/mx-reply>/i, + '', + ) : ((event.content['m.new_content']?.body || - event.content.body) as string), + event.content.body) as string), reply: async (msg: message) => { await intent.sendMessage(event.room_id, coreToMessage(msg)); }, reply_id: event.content['m.relates_to'] ? event.content['m.relates_to']['m.in_reply_to']?.event_id : undefined, - plugin: 'bolt-matrix' + plugin: 'bolt-matrix', }; } @@ -93,6 +92,6 @@ export function coreToMessage(msg: message) { body: msg.content ? msg.content : "*this bridge doesn't support anything except text at the moment*", - msgtype: 'm.text' + msgtype: 'm.text', }; } diff --git a/packages/bolt-matrix/mod.ts b/packages/bolt-matrix/mod.ts index f590382..268434e 100644 --- a/packages/bolt-matrix/mod.ts +++ b/packages/bolt-matrix/mod.ts @@ -1,13 +1,13 @@ import { AppServiceRegistration, Bridge, - bridge_channel, + type bridge_channel, Buffer, existsSync, - lightning, + type lightning, MatrixUser, - message, - plugin + type message, + plugin, } from './deps.ts'; import { coreToMessage, onEvent } from './events.ts'; @@ -31,21 +31,25 @@ export class matrix_plugin extends plugin { domain: this.config.domain, registration: this.config.reg_path, controller: { - onEvent: onEvent.bind(this) + onEvent: onEvent.bind(this), }, roomStore: './config/roomStore.db', userStore: './config/userStore.db', - userActivityStore: './config/userActivityStore.db' + userActivityStore: './config/userActivityStore.db', }); if (!existsSync(this.config.reg_path)) { const reg = new AppServiceRegistration(this.config.appserviceUrl); reg.setAppServiceToken(AppServiceRegistration.generateToken()); reg.setHomeserverToken(AppServiceRegistration.generateToken()); reg.setId(AppServiceRegistration.generateToken()); - reg.setProtocols(['bolt']); + reg.setProtocols(['lightning']); reg.setRateLimited(false); - reg.setSenderLocalpart('bot.bolt'); - reg.addRegexPattern('users', `@bolt-.+_.+:${this.config.domain}`, true); + reg.setSenderLocalpart('bot.lightning'); + reg.addRegexPattern( + 'users', + `@lightning-.+_.+:${this.config.domain}`, + true, + ); reg.outputAsYaml(this.config.reg_path); } this.bot.run(this.config.port || 8081); @@ -61,7 +65,7 @@ export class matrix_plugin extends plugin { channel: bridge_channel, edit_id?: string, reply_id?: string, - edit?: boolean + edit?: boolean, ) { const name = `@${msg.plugin}_${msg.author.id}:${this.config.domain}`; const intent = this.bot.getIntent(name); @@ -71,12 +75,12 @@ export class matrix_plugin extends plugin { if (!storeUser) { storeUser = new MatrixUser(name); } - if (storeUser?.get('avatar') != msg.author.profile) { + if (storeUser?.get('avatar') !== msg.author.profile) { storeUser?.set('avatar', msg.author.profile); const r = await fetch(msg.author.profile || ''); const newMxc = await intent.uploadContent( Buffer.from(await r.arrayBuffer()), - { type: r.headers.get('content-type') || 'image/png' } + { type: r.headers.get('content-type') || 'image/png' }, ); await intent.ensureProfile(msg.author.username, newMxc); await store?.setMatrixUser(storeUser); @@ -89,13 +93,13 @@ export class matrix_plugin extends plugin { 'm.new_content': message, 'm.relates_to': { rel_type: 'm.replace', - event_id: edit_id! - } + event_id: edit_id!, + }, }; } const result = await intent.sendMessage(channel.id, { ...message, - ...editinfo + ...editinfo, }); return result.event_id; } @@ -104,7 +108,7 @@ export class matrix_plugin extends plugin { msg: message, channel: bridge_channel, edit_id?: string, - reply_id?: string + reply_id?: string, ) { return await this.create_message(msg, channel, edit_id, reply_id, true); } @@ -112,13 +116,13 @@ export class matrix_plugin extends plugin { async delete_message( _msg: message, channel: bridge_channel, - delete_id: string + delete_id: string, ) { const intent = this.bot.getIntent(); await intent.botSdkIntent.underlyingClient.redactEvent( channel.id, delete_id, - 'bridge message deletion' + 'bridge message deletion', ); return delete_id; } diff --git a/packages/bolt-revolt/deps.ts b/packages/bolt-revolt/deps.ts index 946fa9d..3ef4501 100644 --- a/packages/bolt-revolt/deps.ts +++ b/packages/bolt-revolt/deps.ts @@ -1,13 +1,13 @@ export { - Client, type API, + Client, type Message, - type TextEmbed + type TextEmbed, } from 'npm:@williamhorning/revolt.js@7.0.0-beta.10'; export { - plugin, type bridge_channel, type deleted_message, type lightning, - type message + type message, + plugin, } from '../lightning/mod.ts'; diff --git a/packages/bolt-revolt/messages.ts b/packages/bolt-revolt/messages.ts index 5b141a0..363b0f9 100644 --- a/packages/bolt-revolt/messages.ts +++ b/packages/bolt-revolt/messages.ts @@ -1,42 +1,41 @@ -import type { API, Message, TextEmbed, message } from './deps.ts'; +import type { API, Message, message, TextEmbed } from './deps.ts'; export async function torevolt( message: message, - masquerade = true + masquerade = true, ): Promise> { const dat: API.DataMessageSend = { - attachments: - message.attachments && message.attachments.length > 0 - ? await Promise.all( - message.attachments.slice(0, 5).map(async ({ file, name }) => { - const formdata = new FormData(); - formdata.append( - 'file', - new File( - [await (await fetch(file)).arrayBuffer()], - name || 'file.name', - { - type: 'application/octet-stream' - } - ) - ); - return ( - await ( - await fetch('https://autumn.revolt.chat/attachments', { - method: 'POST', - body: formdata - }) - ).json() - )?.id; - }) - ) - : undefined, + attachments: message.attachments && message.attachments.length > 0 + ? await Promise.all( + message.attachments.slice(0, 5).map(async ({ file, name }) => { + const formdata = new FormData(); + formdata.append( + 'file', + new File( + [await (await fetch(file)).arrayBuffer()], + name || 'file.name', + { + type: 'application/octet-stream', + }, + ), + ); + return ( + await ( + await fetch('https://autumn.revolt.chat/attachments', { + method: 'POST', + body: formdata, + }) + ).json() + )?.id; + }), + ) + : undefined, content: message.content ? message.content : message.embeds - ? undefined - : 'empty message', - embeds: message.embeds?.map(embed => { + ? undefined + : 'empty message', + embeds: message.embeds?.map((embed) => { if (embed.fields) { for (const field of embed.fields) { embed.description += `\n\n**${field.name}**\n${field.value}`; @@ -46,14 +45,14 @@ export async function torevolt( }), masquerade: masquerade ? { - avatar: message.author.profile, - name: message.author.username.slice(0, 32), - colour: message.author.color - } + avatar: message.author.profile, + name: message.author.username.slice(0, 32), + colour: message.author.color, + } : undefined, replies: message.reply_id ? [{ id: message.reply_id, mention: true }] - : undefined + : undefined, }; if (!dat.attachments) delete dat.attachments; @@ -67,29 +66,27 @@ export async function torevolt( export function tocore(message: Message): message { return { author: { - username: - message.member?.displayName || + username: message.member?.displayName || message.author?.username || `${message.authorId || 'unknown user'} on revolt`, - rawname: - message.author?.username || + rawname: message.author?.username || `${message.authorId || 'unknown user'} on revolt`, profile: message.author?.avatarURL, id: message.authorId || 'unknown', - color: '#FF4654' + color: '#FF4654', }, channel: message.channelId, id: message.id, timestamp: Temporal.Instant.fromEpochMilliseconds( - message.createdAt.valueOf() + message.createdAt.valueOf(), ), - embeds: (message.embeds as TextEmbed[] | undefined)?.map(i => { + embeds: (message.embeds as TextEmbed[] | undefined)?.map((i) => { return { icon_url: i.iconUrl ? i.iconUrl : undefined, type: 'Text', description: i.description ? i.description : undefined, title: i.title ? i.title : undefined, - url: i.url ? i.url : undefined + url: i.url ? i.url : undefined, }; }), plugin: 'bolt-revolt', @@ -102,11 +99,11 @@ export function tocore(message: Message): message { file: `https://autumn.revolt.chat/${tag}/${id}/${filename}`, name: filename, spoiler: isSpoiler, - size: (size || 1) / 1000000 + size: (size || 1) / 1000000, }; - } + }, ), content: message.content, - reply_id: message.replyIds ? message.replyIds[0] : undefined + reply_id: message.replyIds ? message.replyIds[0] : undefined, }; } diff --git a/packages/bolt-revolt/mod.ts b/packages/bolt-revolt/mod.ts index 4e1ecae..23a9e06 100644 --- a/packages/bolt-revolt/mod.ts +++ b/packages/bolt-revolt/mod.ts @@ -2,7 +2,7 @@ import type { bridge_channel, deleted_message, lightning, - message + message, } from './deps.ts'; import { Client, plugin } from './deps.ts'; import { tocore, torevolt } from './messages.ts'; @@ -15,15 +15,15 @@ export class revolt_plugin extends plugin<{ token: string }> { constructor(l: lightning, config: { token: string }) { super(l, config); this.bot = new Client(); - this.bot.on('messageCreate', message => { + this.bot.on('messageCreate', (message) => { if (message.systemMessage) return; this.emit('create_message', tocore(message)); }); - this.bot.on('messageUpdate', message => { + this.bot.on('messageUpdate', (message) => { if (message.systemMessage) return; this.emit('edit_message', tocore(message)); }); - this.bot.on('messageDelete', message => { + this.bot.on('messageDelete', (message) => { if (message.systemMessage) return; this.emit('delete_message', { channel: message.channelId, @@ -31,9 +31,9 @@ export class revolt_plugin extends plugin<{ token: string }> { plugin: 'bolt-revolt', timestamp: message.editedAt ? Temporal.Instant.fromEpochMilliseconds( - message.editedAt?.getUTCMilliseconds() - ) - : Temporal.Now.instant() + message.editedAt?.getUTCMilliseconds(), + ) + : Temporal.Now.instant(), }); }); this.bot.loginBot(this.config.token); @@ -51,11 +51,11 @@ export class revolt_plugin extends plugin<{ token: string }> { msg: message, bridge: bridge_channel, _: undefined, - reply_id?: string + reply_id?: string, ) { const channel = await this.bot.channels.fetch(bridge.id); const result = await channel.sendMessage( - await torevolt({ ...msg, reply_id }) + await torevolt({ ...msg, reply_id }), ); return result.id; } @@ -64,7 +64,7 @@ export class revolt_plugin extends plugin<{ token: string }> { msg: message, bridge: bridge_channel, edit_id: string, - reply_id?: string + reply_id?: string, ) { const message = await this.bot.messages.fetch(bridge.id, edit_id); await message.edit(await torevolt({ ...msg, reply_id })); diff --git a/packages/lightning/mod.ts b/packages/lightning/mod.ts index eb1fd22..d46574f 100644 --- a/packages/lightning/mod.ts +++ b/packages/lightning/mod.ts @@ -6,9 +6,9 @@ export * from './src/bridges/types.ts'; export type { - command, - command_arguments, - command_options + command, + command_arguments, + command_options, } from './src/commands.ts'; export * from './src/errors.ts'; export * from './src/lightning.ts'; diff --git a/packages/lightning/readme.md b/packages/lightning/readme.md index 1609df0..12e08a1 100644 --- a/packages/lightning/readme.md +++ b/packages/lightning/readme.md @@ -17,7 +17,7 @@ export default { plugins: [ discord_plugin.new({ // ... - }) - ] + }), + ], } as config; ``` diff --git a/packages/lightning/src/bridges/cmd_internals.ts b/packages/lightning/src/bridges/cmd_internals.ts index d9de5d9..887d90c 100644 --- a/packages/lightning/src/bridges/cmd_internals.ts +++ b/packages/lightning/src/bridges/cmd_internals.ts @@ -4,16 +4,16 @@ import { exists, get_bridge, get_channel_bridge, - set_bridge + set_bridge, } from './db_internals.ts'; export async function join( - opts: command_arguments + opts: command_arguments, ): Promise<[boolean, string]> { if (await exists(opts.lightning, `lightning-bchannel-${opts.channel}`)) { return [ false, - "To do this, you can't be in a bridge. Try leaving your bridge first." + "To do this, you can't be in a bridge. Try leaving your bridge first.", ]; } @@ -22,7 +22,7 @@ export async function join( if (!id) { return [ false, - 'You need to provide a name your bridge. Try `join --name=` instead.' + 'You need to provide a name your bridge. Try `join --name=` instead.', ]; } @@ -32,13 +32,13 @@ export async function join( allow_editing: false, channels: [], id, - use_rawname: false + use_rawname: false, }; bridge.channels.push({ id: opts.channel, plugin: opts.plugin, - data: await plugin!.create_bridge(opts.channel) + data: await plugin!.create_bridge(opts.channel), }); await set_bridge(opts.lightning, bridge); @@ -47,7 +47,7 @@ export async function join( } export async function leave( - opts: command_arguments + opts: command_arguments, ): Promise<[boolean, string]> { const bridge = await get_channel_bridge(opts.lightning, opts.channel); @@ -58,8 +58,8 @@ export async function leave( await set_bridge(opts.lightning, { ...bridge, channels: bridge.channels.filter( - i => i.id !== opts.channel && i.plugin !== opts.plugin - ) + (i) => i.id !== opts.channel && i.plugin !== opts.plugin, + ), }); await del_key(opts.lightning, `lightning-bchannel-${opts.channel}`); @@ -68,10 +68,11 @@ export async function leave( } export async function reset(opts: command_arguments) { - if (!opts.opts.name) + if (!opts.opts.name) { opts.opts.name = (await get_channel_bridge(opts.lightning, opts.channel))?.id || opts.channel; + } let [ok, text] = await leave(opts); if (!ok) return text; diff --git a/packages/lightning/src/bridges/db_internals.ts b/packages/lightning/src/bridges/db_internals.ts index 7c38286..65e99db 100644 --- a/packages/lightning/src/bridges/db_internals.ts +++ b/packages/lightning/src/bridges/db_internals.ts @@ -7,7 +7,7 @@ export async function exists(l: lightning, key: string) { export async function get_json( l: lightning, - key: string + key: string, ): Promise { const reply = await l.redis.sendCommand(['GET', key]); if (!reply || reply === 'OK') return; @@ -42,7 +42,7 @@ export async function set_bridge(l: lightning, bridge: bridge_document) { await l.redis.sendCommand([ 'SET', `lightning-bchannel-${channel.id}`, - bridge.id + bridge.id, ]); } } diff --git a/packages/lightning/src/bridges/handle_message.ts b/packages/lightning/src/bridges/handle_message.ts index 4d89205..682a6b1 100644 --- a/packages/lightning/src/bridges/handle_message.ts +++ b/packages/lightning/src/bridges/handle_message.ts @@ -4,26 +4,25 @@ import type { deleted_message, message } from '../messages.ts'; import { get_channel_bridge, get_message_bridge, - set_json + set_json, } from './db_internals.ts'; import type { bridge_channel, bridge_message } from './types.ts'; export async function handle_message( lightning: lightning, msg: message | deleted_message, - type: 'create_message' | 'edit_message' | 'delete_message' + type: 'create_message' | 'edit_message' | 'delete_message', ): Promise { - const bridge = - type === 'create_message' - ? await get_channel_bridge(lightning, msg.channel) - : await get_message_bridge(lightning, msg.id); + const bridge = type === 'create_message' + ? await get_channel_bridge(lightning, msg.channel) + : await get_message_bridge(lightning, msg.id); if (!bridge) return; if (type !== 'create_message' && bridge.allow_editing !== true) return; const channels = bridge.channels.filter( - i => i.id !== msg.channel && i.plugin !== msg.plugin + (i) => i.id !== msg.channel && i.plugin !== msg.plugin, ); if (channels.length < 1) return; @@ -41,7 +40,7 @@ export async function handle_message( if (!plugin || !plugin[type]) { await log_error( new Error(`plugin ${channel.plugin} doesn't have ${type}_message`), - { channel, bridged_id } + { channel, bridged_id }, ); continue; } @@ -55,7 +54,7 @@ export async function handle_message( msg as message, channel, bridged_id?.id!, - reply_id + reply_id, ); } catch (e) { if (type === 'delete_message') continue; @@ -68,9 +67,9 @@ export async function handle_message( await log_error( new Error( `Failed to send error for ${type}_message to ${channel.plugin}`, - { cause: e } + { cause: e }, ), - { channel, bridged_id } + { channel, bridged_id }, ); continue; } @@ -84,20 +83,20 @@ export async function handle_message( for (const i of messages) { await set_json(lightning, `lightning-bridged-${i.id}`, { ...bridge, - messages + messages, }); } await set_json(lightning, `lightning-bridged-${msg.id}`, { ...bridge, - messages + messages, }); } async function get_reply_id( lightning: lightning, msg: message, - channel: bridge_channel + channel: bridge_channel, ) { if (msg.reply_id) { try { @@ -106,7 +105,7 @@ async function get_reply_id( if (!bridged) return; const bridge_channel = bridged.messages?.find( - i => i.channel === channel.id && i.plugin === channel.plugin + (i) => i.channel === channel.id && i.plugin === channel.plugin, ); return bridge_channel?.id; diff --git a/packages/lightning/src/bridges/setup_bridges.ts b/packages/lightning/src/bridges/setup_bridges.ts index 0bb3512..7f687ae 100644 --- a/packages/lightning/src/bridges/setup_bridges.ts +++ b/packages/lightning/src/bridges/setup_bridges.ts @@ -4,21 +4,21 @@ import { exists } from './db_internals.ts'; import { handle_message } from './handle_message.ts'; export function setup_bridges(l: lightning) { - l.on('create_message', async msg => { - await new Promise(res => setTimeout(res, 15)); + l.on('create_message', async (msg) => { + await new Promise((res) => setTimeout(res, 15)); if (await exists(l, `lightning-bridged-${msg.id}`)) return; l.emit(`create_nonbridged_message`, msg); handle_message(l, msg, 'create_message'); }); - l.on('edit_message', async msg => { - await new Promise(res => setTimeout(res, 15)); + l.on('edit_message', async (msg) => { + await new Promise((res) => setTimeout(res, 15)); if (await exists(l, `lightning-bridged-${msg.id}`)) return; handle_message(l, msg, 'edit_message'); }); - l.on('delete_message', async msg => { - await new Promise(res => setTimeout(res, 15)); + l.on('delete_message', async (msg) => { + await new Promise((res) => setTimeout(res, 15)); handle_message(l, msg, 'delete_message'); }); @@ -31,32 +31,32 @@ export function setup_bridges(l: lightning) { { name: 'join', description: 'join a bridge', - execute: async opts => (await join(opts))[1], - options: { argument_name: 'name', argument_required: true } + execute: async (opts) => (await join(opts))[1], + options: { argument_name: 'name', argument_required: true }, }, { name: 'leave', description: 'leave a bridge', - execute: async opts => (await leave(opts))[1] + execute: async (opts) => (await leave(opts))[1], }, { name: 'reset', description: 'reset a bridge', - execute: async opts => await reset(opts), - options: { argument_name: 'name' } + execute: async (opts) => await reset(opts), + options: { argument_name: 'name' }, }, { name: 'toggle', description: 'toggle a setting on a bridge', - execute: async opts => await toggle(opts), - options: { argument_name: 'setting', argument_required: true } + execute: async (opts) => await toggle(opts), + options: { argument_name: 'setting', argument_required: true }, }, { name: 'status', description: 'see what bridges you are in', - execute: async opts => await status(opts) - } - ] - } + execute: async (opts) => await status(opts), + }, + ], + }, }); } diff --git a/packages/lightning/src/bridges/types.ts b/packages/lightning/src/bridges/types.ts index 3718eb6..e3a9669 100644 --- a/packages/lightning/src/bridges/types.ts +++ b/packages/lightning/src/bridges/types.ts @@ -30,4 +30,4 @@ export interface bridge_document { messages?: bridge_message[]; /** whether or not to use nicknames */ use_rawname: boolean; -} \ No newline at end of file +} diff --git a/packages/lightning/src/cli/migrations.ts b/packages/lightning/src/cli/migrations.ts index d1a5f39..d49bd5c 100644 --- a/packages/lightning/src/cli/migrations.ts +++ b/packages/lightning/src/cli/migrations.ts @@ -3,7 +3,7 @@ import { get_migrations, mongo_to_redis, versions } from '../migrations.ts'; const redis_hostname = prompt( `what hostname is used by your redis instance?`, - 'localhost' + 'localhost', ); const redis_port = prompt(`what port is used by your redis instance?`, '6379'); @@ -12,8 +12,8 @@ if (!redis_hostname || !redis_port) Deno.exit(); const redis = new RedisClient( await Deno.connect({ hostname: redis_hostname, - port: Number(redis_port) - }) + port: Number(redis_port), + }), ); console.log('connected to redis!'); @@ -40,7 +40,7 @@ if (mongo) { const final_data = ( await collection.find({ _id: { $regex: '.*' } }).toArray() - ).map(i => [i._id, i]) as [string, unknown][]; + ).map((i) => [i._id, i]) as [string, unknown][]; console.log(`downloaded data from mongo!`); console.log(`applying migrations...`); @@ -73,7 +73,7 @@ if (mongo) { try { redis_data.push([ key, - JSON.parse((await redis.sendCommand(['GET', key])) as string) + JSON.parse((await redis.sendCommand(['GET', key])) as string), ]); } catch { console.log(`skipping ${key} due to invalid JSON...`); @@ -98,7 +98,7 @@ const file = await Deno.makeTempFile(); await Deno.writeTextFile(file, JSON.stringify(final_data)); const write = confirm( - `do you want the data in ${file} to be written to the database?` + `do you want the data in ${file} to be written to the database?`, ); if (!write) Deno.exit(); diff --git a/packages/lightning/src/cli/mod.ts b/packages/lightning/src/cli/mod.ts index 31cd89c..4072e30 100644 --- a/packages/lightning/src/cli/mod.ts +++ b/packages/lightning/src/cli/mod.ts @@ -1,9 +1,9 @@ import { parseArgs } from '../../deps.ts'; import { log_error } from '../errors.ts'; -import { lightning, type config } from '../lightning.ts'; +import { type config, lightning } from '../lightning.ts'; const _ = parseArgs(Deno.args, { - string: ['config'] + string: ['config'], }); const cmd = _._[0]; @@ -21,8 +21,8 @@ if (cmd === 'version') { cfg, await Deno.connect({ hostname: cfg.redis_host || 'localhost', - port: cfg.redis_port || 6379 - }) + port: cfg.redis_port || 6379, + }), ); } catch (e) { await log_error(e); diff --git a/packages/lightning/src/cmds.ts b/packages/lightning/src/cmds.ts index e475f4d..cde0f89 100644 --- a/packages/lightning/src/cmds.ts +++ b/packages/lightning/src/cmds.ts @@ -7,16 +7,16 @@ export const default_cmds = [ name: 'help', description: 'get help', execute: () => - 'check out [the docs](https://williamhorning.dev/bolt/) for help.' - } + 'check out [the docs](https://williamhorning.dev/bolt/) for help.', + }, ], [ 'version', { name: 'version', description: 'get the bots version', - execute: () => 'hello from v0.7.0!' - } + execute: () => 'hello from v0.7.0!', + }, ], [ 'ping', @@ -24,9 +24,11 @@ export const default_cmds = [ name: 'ping', description: 'pong', execute: ({ timestamp }) => - `Pong! 🏓 ${Temporal.Now.instant() - .since(timestamp) - .total('milliseconds')}ms` - } - ] + `Pong! 🏓 ${ + Temporal.Now.instant() + .since(timestamp) + .total('milliseconds') + }ms`, + }, + ], ] as [string, command][]; diff --git a/packages/lightning/src/commands.ts b/packages/lightning/src/commands.ts index 61293cc..eb76bcf 100644 --- a/packages/lightning/src/commands.ts +++ b/packages/lightning/src/commands.ts @@ -6,7 +6,7 @@ import { create_message, type message } from './messages.ts'; export function setup_commands(l: lightning) { const prefix = l.config.cmd_prefix || 'l!'; - l.on('create_nonbridged_message', m => { + l.on('create_nonbridged_message', (m) => { if (!m.content?.startsWith(prefix)) return; const { @@ -19,11 +19,11 @@ export function setup_commands(l: lightning) { cmd: cmd as string, subcmd: subcmd as string, opts, - ...m + ...m, }); }); - l.on('run_command', i => run_command({ lightning: l, ...i })); + l.on('run_command', (i) => run_command({ lightning: l, ...i })); } /** arguments passed to a command */ @@ -72,12 +72,12 @@ async function run_command(args: command_arguments) { let reply; try { - const cmd = - args.lightning.commands.get(args.cmd) || + const cmd = args.lightning.commands.get(args.cmd) || args.lightning.commands.get('help')!; - const exec = - cmd.options?.subcommands?.find(i => i.name === args.subcmd)?.execute || + const exec = cmd.options?.subcommands?.find((i) => + i.name === args.subcmd + )?.execute || cmd.execute; reply = create_message(await exec(args)); diff --git a/packages/lightning/src/errors.ts b/packages/lightning/src/errors.ts index 87151bc..c3a44db 100644 --- a/packages/lightning/src/errors.ts +++ b/packages/lightning/src/errors.ts @@ -1,4 +1,4 @@ -import { create_message, type message } from "./messages.ts"; +import { create_message, type message } from './messages.ts'; /** the error returned from log_error */ export interface err { @@ -30,8 +30,8 @@ export async function log_error( method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ - embeds: [{ title: e.message, description: uuid }] - }) + embeds: [{ title: e.message, description: uuid }], + }), }) ).text(); } @@ -40,7 +40,7 @@ export async function log_error( console.error(e, extra); const message = create_message( - `Something went wrong! [Look here](https://williamhorning.dev/bolt) for help.\n\`\`\`\n${e.message}\n${uuid}\n\`\`\`` + `Something went wrong! [Look here](https://williamhorning.dev/bolt) for help.\n\`\`\`\n${e.message}\n${uuid}\n\`\`\``, ); return { e, uuid, extra, message }; diff --git a/packages/lightning/src/lightning.ts b/packages/lightning/src/lightning.ts index 3c6dcbd..81ee5d1 100644 --- a/packages/lightning/src/lightning.ts +++ b/packages/lightning/src/lightning.ts @@ -1,7 +1,7 @@ import { EventEmitter, RedisClient } from '../deps.ts'; import { setup_bridges } from './bridges/setup_bridges.ts'; -import { default_cmds } from "./cmds.ts"; -import { setup_commands, type command } from './commands.ts'; +import { default_cmds } from './cmds.ts'; +import { type command, setup_commands } from './commands.ts'; import type { create_plugin, plugin, plugin_events } from './plugins.ts'; /** configuration options for lightning */ diff --git a/packages/lightning/src/messages.ts b/packages/lightning/src/messages.ts index 923b0f4..0684db4 100644 --- a/packages/lightning/src/messages.ts +++ b/packages/lightning/src/messages.ts @@ -8,14 +8,14 @@ export function create_message(text: string): message { username: 'lightning', profile: 'https://williamhorning.dev/assets/lightning.png', rawname: 'lightning', - id: 'lightning' + id: 'lightning', }, content: text, channel: '', id: '', reply: async () => {}, timestamp: Temporal.Now.instant(), - plugin: 'lightning' + plugin: 'lightning', }; return data; } diff --git a/packages/lightning/src/migrations.ts b/packages/lightning/src/migrations.ts index dbd36b9..e462658 100644 --- a/packages/lightning/src/migrations.ts +++ b/packages/lightning/src/migrations.ts @@ -5,8 +5,8 @@ */ export function get_migrations(from: versions, to: versions): migration[] { return migrations.slice( - migrations.findIndex(i => i.from === from), - migrations.findLastIndex(i => i.to === to) + 1 + migrations.findIndex((i) => i.from === from), + migrations.findLastIndex((i) => i.to === to) + 1, ); } @@ -25,16 +25,16 @@ export function mongo_to_redis(items: [string, unknown][]) { id, { allow_editing: val.settings?.editing_allowed ?? false, - channels: val.platforms.map(i => { + channels: val.platforms.map((i) => { return { id: i.channel, data: i.senddata, - plugin: i.plugin + plugin: i.plugin, }; }), id, - use_rawname: val.settings?.realnames ?? false - } + use_rawname: val.settings?.realnames ?? false, + }, ]; }); } @@ -54,7 +54,7 @@ export enum versions { /** versions 0.5 through 0.6 */ Five = '0.5', /** versions 0.7 and above*/ - Seven = '0.7' + Seven = '0.7', } /** the internal list of migrations */ @@ -62,7 +62,7 @@ const migrations = [ { from: versions.Five, to: versions.Seven, - translate: items => + translate: (items) => items.flatMap(([key, val]) => { if (!key.startsWith('lightning-bridge-')) return []; @@ -75,7 +75,7 @@ const migrations = [ senddata: unknown; id: string; }[] - ).map(i => { + ).map((i) => { return { id: i.channel, data: i.senddata, plugin: i.plugin }; }); const value = { @@ -83,10 +83,10 @@ const migrations = [ channels, id, messages: val, - use_rawname: false + use_rawname: false, }; return [[id, value]]; - }) - } + }), + }, ] as migration[]; diff --git a/packages/lightning/src/plugins.ts b/packages/lightning/src/plugins.ts index 4eb5f58..c9d573b 100644 --- a/packages/lightning/src/plugins.ts +++ b/packages/lightning/src/plugins.ts @@ -6,7 +6,7 @@ import type { deleted_message, message } from './messages.ts'; /** the way to make a plugin */ export interface create_plugin< - plugin_type extends plugin + plugin_type extends plugin, > { /** the actual constructor of the plugin */ type: new (l: lightning, config: plugin_type['config']) => plugin_type; @@ -42,7 +42,7 @@ export abstract class plugin extends EventEmitter { /** create a new plugin instance */ static new>( this: new (l: lightning, config: T['config']) => T, - config: T['config'] + config: T['config'], ): create_plugin { return { type: this, config, support: ['0.7.0'] }; } @@ -61,7 +61,7 @@ export abstract class plugin extends EventEmitter { message: message, channel: bridge_channel, edit_id?: string, - reply_id?: string + reply_id?: string, ): Promise; /** this is used to bridge an EDITED message */ @@ -69,7 +69,7 @@ export abstract class plugin extends EventEmitter { message: message, channel: bridge_channel, edit_id: string, - reply_id?: string + reply_id?: string, ): Promise; /** this is used to bridge a DELETED message */ @@ -77,6 +77,6 @@ export abstract class plugin extends EventEmitter { message: deleted_message, channel: bridge_channel, delete_id: string, - reply_id?: string + reply_id?: string, ): Promise; }