Skip to content

Commit

Permalink
refactor: slashify /snipe (#2683)
Browse files Browse the repository at this point in the history
  • Loading branch information
kyranet authored Oct 19, 2024
1 parent b027179 commit 1641c6a
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 26 deletions.
44 changes: 34 additions & 10 deletions src/commands/Misc/snipe.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,55 @@
import { getSupportedLanguageT } from '#lib/i18n';
import { LanguageKeys } from '#lib/i18n/languageKeys';
import { SkyraCommand } from '#lib/structures';
import { PermissionLevels, type GuildMessage } from '#lib/types';
import { Urls } from '#utils/constants';
import { getSnipedMessage } from '#utils/functions';
import { getColor, getContent, getFullEmbedAuthor, getImages, setMultipleEmbedImages } from '#utils/util';
import { EmbedBuilder } from '@discordjs/builders';
import { EmbedBuilder, chatInputApplicationCommandMention } from '@discordjs/builders';
import { ApplyOptions } from '@sapphire/decorators';
import { CommandOptionsRunTypeEnum } from '@sapphire/framework';
import { ApplicationCommandRegistry, CommandOptionsRunTypeEnum } from '@sapphire/framework';
import { send } from '@sapphire/plugin-editable-commands';
import { PermissionFlagsBits } from 'discord.js';
import { applyLocalizedBuilder } from '@sapphire/plugin-i18next';
import { PermissionFlagsBits, type GuildTextBasedChannel } from 'discord.js';

const Root = LanguageKeys.Commands.Snipe;

@ApplyOptions<SkyraCommand.Options>({
aliases: ['sniped'],
description: LanguageKeys.Commands.Misc.SnipeDescription,
detailedDescription: LanguageKeys.Commands.Misc.SnipeExtended,
description: Root.Description,
detailedDescription: LanguageKeys.Commands.Shared.SlashOnlyDetailedDescription,
requiredClientPermissions: [PermissionFlagsBits.EmbedLinks],
permissionLevel: PermissionLevels.Moderator,
runIn: [CommandOptionsRunTypeEnum.GuildAny]
})
export class UserCommand extends SkyraCommand {
public override messageRun(message: GuildMessage, args: SkyraCommand.Args) {
const sniped = getSnipedMessage(message.channel);
if (sniped === null) this.error(LanguageKeys.Commands.Misc.SnipeEmpty);
public override registerApplicationCommands(registry: ApplicationCommandRegistry) {
registry.registerChatInputCommand((builder) =>
applyLocalizedBuilder(builder, Root.Name, Root.Description)
.setDMPermission(false)
.setDefaultMemberPermissions(PermissionFlagsBits.KickMembers)
);
}

public override async messageRun(message: GuildMessage, args: SkyraCommand.Args) {
const content = args.t(LanguageKeys.Commands.Shared.DeprecatedMessage, {
command: chatInputApplicationCommandMention(this.name, this.getGlobalCommandId())
});

return send(message, { content });
}

public override chatInputRun(interaction: SkyraCommand.ChatInputInteraction) {
const t = getSupportedLanguageT(interaction);
const sniped = getSnipedMessage(interaction.channel as GuildTextBasedChannel);
if (sniped === null) {
const content = t(Root.MessageEmpty);
return interaction.reply({ content, ephemeral: true });
}

const embed = new EmbedBuilder()
.setURL(Urls.Website)
.setFooter({ text: args.t(LanguageKeys.Commands.Misc.SnipeTitle) })
.setFooter({ text: t(Root.EmbedTitle) })
.setColor(getColor(sniped))
.setAuthor(getFullEmbedAuthor(sniped.author))
.setTimestamp(sniped.createdTimestamp);
Expand All @@ -34,6 +58,6 @@ export class UserCommand extends SkyraCommand {
if (content !== null) embed.setDescription(content);

const embeds = setMultipleEmbedImages(embed, getImages(sniped));
return send(message, { embeds });
return interaction.reply({ embeds, ephemeral: true });
}
}
8 changes: 0 additions & 8 deletions src/languages/en-US/commands/misc.json

This file was deleted.

6 changes: 6 additions & 0 deletions src/languages/en-US/commands/snipe.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "snipe",
"description": "Retrieve the last recently deleted message from a channel",
"messageEmpty": "There are no sniped messages in this channel.",
"embedTitle": "Sniped Message"
}
2 changes: 1 addition & 1 deletion src/lib/i18n/languageKeys/keys/Commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export * as Games from '#lib/i18n/languageKeys/keys/commands/Games';
export * as General from '#lib/i18n/languageKeys/keys/commands/General';
export * as Info from '#lib/i18n/languageKeys/keys/commands/Info';
export * as Management from '#lib/i18n/languageKeys/keys/commands/Management';
export * as Misc from '#lib/i18n/languageKeys/keys/commands/Misc';
export * as Snipe from '#lib/i18n/languageKeys/keys/commands/Snipe';
export * as Moderation from '#lib/i18n/languageKeys/keys/commands/Moderation';
export * as Shared from '#lib/i18n/languageKeys/keys/commands/Shared';
export * as System from '#lib/i18n/languageKeys/keys/commands/System';
Expand Down
7 changes: 0 additions & 7 deletions src/lib/i18n/languageKeys/keys/commands/Misc.ts

This file was deleted.

6 changes: 6 additions & 0 deletions src/lib/i18n/languageKeys/keys/commands/Snipe.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { T } from '#lib/types';

export const Name = T('commands/snipe:name');
export const Description = T('commands/snipe:description');
export const MessageEmpty = T('commands/snipe:messageEmpty');
export const EmbedTitle = T('commands/snipe:embedTitle');

0 comments on commit 1641c6a

Please sign in to comment.