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

Commit

Permalink
Fix sendMessageUpdates, reply to CTCP VERSION, fix formatting (#54)
Browse files Browse the repository at this point in the history
* Reply to CTCP VERSION

* Use deps.ts

* Fix message updates

* Update default urlAttachment format

* Update README
  • Loading branch information
aronson authored Nov 4, 2023
1 parent fd7db38 commit 4e930b3
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 5 deletions.
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/[email protected]/plugins/nick
export type { CtcpActionEvent } from 'https://deno.land/x/[email protected]/plugins/action.ts';
export type { InviteEvent } from 'https://deno.land/x/[email protected]/plugins/invite.ts';
export type { AnyRawCommand } from 'https://deno.land/x/[email protected]/core/protocol.ts';
export type { CtcpVersionEvent } from 'https://deno.land/x/[email protected]/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

0 comments on commit 4e930b3

Please sign in to comment.