From 4e930b33a8e4a0847126a666246854a23402d488 Mon Sep 17 00:00:00 2001 From: aronson Date: Sat, 4 Nov 2023 05:22:55 -0500 Subject: [PATCH] Fix sendMessageUpdates, reply to CTCP VERSION, fix formatting (#54) * Reply to CTCP VERSION * Use deps.ts * Fix message updates * Update default urlAttachment format * Update README --- README.md | 2 +- lib/deps.ts | 1 + lib/discordClient.ts | 2 +- lib/ircClient.ts | 6 ++++++ lib/mediator.ts | 6 +++--- 5 files changed, 12 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index b30b691..e5784aa 100644 --- a/README.md +++ b/README.md @@ -187,7 +187,7 @@ First you need to create a Discord bot user, which you can do by following the i // Patterns, represented by {$patternName}, are replaced when sending messages "commandPrelude": "Command sent by {$nickname}", // Message sent before a command "ircText": "<{$displayUsername} [@{$discordUsername}]> {$text}", // When sending a message to IRC - "urlAttachment": "<{$displayUsername}> {$attachmentURL}", // When sending a Discord attachment to IRC + "urlAttachment": "<{$displayUsername} [@{$discordUsername}]> {$attachmentURL}", // When sending a Discord attachment to IRC "discord": "**<{$author}>** {$withMentions}", // When sending a message to Discord // Other patterns that can be used: // {$discordChannel} (e.g. #general) diff --git a/lib/deps.ts b/lib/deps.ts index 4d2252b..8a5aff9 100644 --- a/lib/deps.ts +++ b/lib/deps.ts @@ -14,6 +14,7 @@ export type { NicklistEvent } from 'https://deno.land/x/irc@v0.15.0/plugins/nick export type { CtcpActionEvent } from 'https://deno.land/x/irc@v0.15.0/plugins/action.ts'; export type { InviteEvent } from 'https://deno.land/x/irc@v0.15.0/plugins/invite.ts'; export type { AnyRawCommand } from 'https://deno.land/x/irc@v0.15.0/core/protocol.ts'; +export type { CtcpVersionEvent } from 'https://deno.land/x/irc@v0.15.0/plugins/version.ts'; // Harmony/Discord exports export { AllowedMentionType, diff --git a/lib/discordClient.ts b/lib/discordClient.ts index b5cde1d..fbbc0f4 100644 --- a/lib/discordClient.ts +++ b/lib/discordClient.ts @@ -37,7 +37,7 @@ export class DiscordClient extends Client { async bindNotify(notify: (m: Message, b: boolean) => Promise, mapper: ChannelMapper) { this.on('messageCreate', async (ev) => await notify(ev, false)); - this.on('messageUpdate', async (ev) => { + this.on('messageUpdate', async (_, ev) => { if (!this.sendMessageUpdates) return; await notify(ev, true); }); diff --git a/lib/ircClient.ts b/lib/ircClient.ts index 4f91f48..3635f44 100644 --- a/lib/ircClient.ts +++ b/lib/ircClient.ts @@ -5,6 +5,7 @@ import { AnyRawCommand, ClientError, ClientOptions, + CtcpVersionEvent, Dlog, InviteEvent, IrcClient, @@ -301,4 +302,9 @@ export class CustomIrcClient extends IrcClient { `Attempting to reconnect to server ${addr.hostname}:${addr.port}...`, ); } + @Event('ctcp_version') + on_ctcp_version(cmd: CtcpVersionEvent) { + if (!cmd.source) return; + this.ctcp(cmd.source.name, 'VERSION', 'Discord-IRC'); + } } diff --git a/lib/mediator.ts b/lib/mediator.ts index 311dd0e..0d480ac 100644 --- a/lib/mediator.ts +++ b/lib/mediator.ts @@ -107,7 +107,7 @@ export class Mediator { this.formatIRCText = config.format?.ircText || '<{$displayUsername} [@{$discordUsername}]> {$text}'; this.formatURLAttachment = config.format?.urlAttachment || - '<{$displayUsername}> {$attachmentURL}'; + '<{$displayUsername} [@{$discordUsername}]> {$attachmentURL}'; // "{$keyName}" => "variableValue" // side: "Discord" or "IRC" @@ -412,7 +412,7 @@ export class Mediator { } } - async notifyToIrc(message: DiscordMessage): Promise { + async notifyToIrc(message: DiscordMessage, update = false): Promise { if (message.content.trim() === '/names') return; if (!message.channel.isGuildText()) return; // return early if message was in channel we don't post to @@ -421,7 +421,7 @@ export class Mediator { } const ircChannel = this.channelMapping.discordIdToMapping.get(message.channel.id)?.ircChannel; if (!ircChannel) return; - await this.sendToIRC(message); + await this.sendToIRC(message, update); } shouldIgnoreByPattern(text: string, ircChannel: string): boolean {