diff --git a/backend/src/plugins/Utility.ts b/backend/src/plugins/Utility.ts index 3fc0c7f2..645d94b5 100644 --- a/backend/src/plugins/Utility.ts +++ b/backend/src/plugins/Utility.ts @@ -29,6 +29,7 @@ import { get, getInviteCodesInString, isSnowflake, + messageLink, MINUTES, multiSorter, noop, @@ -72,6 +73,7 @@ const ConfigSchema = t.type({ can_vcmove: t.boolean, can_help: t.boolean, can_about: t.boolean, + can_context: t.boolean, }); type TConfigSchema = t.TypeOf; @@ -125,6 +127,7 @@ export class UtilityPlugin extends ZeppelinPlugin { can_vcmove: false, can_help: false, can_about: false, + can_context: false, }, overrides: [ { @@ -139,6 +142,7 @@ export class UtilityPlugin extends ZeppelinPlugin { can_nickname: true, can_vcmove: true, can_help: true, + can_context: true, }, }, { @@ -1030,6 +1034,30 @@ export class UtilityPlugin extends ZeppelinPlugin { msg.channel.createMessage(`Message source: ${url}`); } + @d.command("context", " ", { + extra: { + info: { + description: "Get a link to the context of the specified message", + basicUsage: "!context 94882524378968064 650391267720822785", + }, + }, + }) + @d.permission("can_context") + async contextCmd(msg: Message, args: { channel: Channel; messageId: string }) { + if (!(args.channel instanceof TextChannel)) { + this.sendErrorMessage(msg.channel, "Channel must be a text channel"); + return; + } + + const previousMessage = (await this.bot.getMessages(args.channel.id, 1, args.messageId))[0]; + if (!previousMessage) { + this.sendErrorMessage(msg.channel, "Message context not found"); + return; + } + + msg.channel.createMessage(messageLink(this.guildId, previousMessage.channel.id, previousMessage.id)); + } + @d.command("vcmove", " ", { extra: { info: { diff --git a/backend/src/utils.ts b/backend/src/utils.ts index 4b1d6740..2005f862 100644 --- a/backend/src/utils.ts +++ b/backend/src/utils.ts @@ -947,6 +947,7 @@ export function verboseChannelMention(channel: GuildChannel): string { } export function messageLink(message: Message): string; +export function messageLink(guildId: string, channelId: string, messageId: string): string; export function messageLink(guildIdOrMessage: string | Message | null, channelId?: string, messageId?: string): string { let guildId; if (guildIdOrMessage == null) {