Skip to content
This repository has been archived by the owner on Apr 24, 2024. It is now read-only.

Fix sendMessageUpdates, reply to CTCP VERSION, fix formatting #54

Merged
merged 5 commits into from
Nov 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions lib/deps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion lib/discordClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export class DiscordClient extends Client {

async bindNotify(notify: (m: Message, b: boolean) => Promise<void>, 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);
});
Expand Down
6 changes: 6 additions & 0 deletions lib/ircClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
AnyRawCommand,
ClientError,
ClientOptions,
CtcpVersionEvent,
Dlog,
InviteEvent,
IrcClient,
Expand Down Expand Up @@ -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');
}
}
6 changes: 3 additions & 3 deletions lib/mediator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -412,7 +412,7 @@ export class Mediator {
}
}

async notifyToIrc(message: DiscordMessage): Promise<void> {
async notifyToIrc(message: DiscordMessage, update = false): Promise<void> {
if (message.content.trim() === '/names') return;
if (!message.channel.isGuildText()) return;
// return early if message was in channel we don't post to
Expand All @@ -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 {
Expand Down