Add !context utility command

This commit is contained in:
Dragory 2019-11-30 19:54:44 +02:00
parent 7df1bb91d2
commit 64e1fbc10c
2 changed files with 29 additions and 0 deletions

View file

@ -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<typeof ConfigSchema>;
@ -125,6 +127,7 @@ export class UtilityPlugin extends ZeppelinPlugin<TConfigSchema> {
can_vcmove: false,
can_help: false,
can_about: false,
can_context: false,
},
overrides: [
{
@ -139,6 +142,7 @@ export class UtilityPlugin extends ZeppelinPlugin<TConfigSchema> {
can_nickname: true,
can_vcmove: true,
can_help: true,
can_context: true,
},
},
{
@ -1030,6 +1034,30 @@ export class UtilityPlugin extends ZeppelinPlugin<TConfigSchema> {
msg.channel.createMessage(`Message source: ${url}`);
}
@d.command("context", "<channel:channel> <messageId:string>", {
extra: {
info: <CommandInfo>{
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", "<member:resolvedMember> <channel:string$>", {
extra: {
info: <CommandInfo>{

View file

@ -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) {