Skip to content

Commit

Permalink
feat(command): add avatar command
Browse files Browse the repository at this point in the history
  • Loading branch information
tinarskii committed Oct 27, 2022
1 parent ea90382 commit 32aa8f7
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .github/CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,4 @@ by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/div

For answers to common questions about this code of conduct, see the FAQ at
https://www.contributor-covenant.org/faq. Translations are available at
https://www.contributor-covenant.org/translations.
https://www.contributor-covenant.org/translations.
2 changes: 1 addition & 1 deletion .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ merged into the main branch first.

We've provided some of the issues templates to use in various situations.
It'll make the process of writing an issue easier. But if none of the suit your fit,
You could write it by yourself.
You could write it by yourself.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/bug.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ labels: bug

## More information

- Any other information you want to add
- Any other information you want to add
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/feature.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ labels: improvement

## What's the benefit?

- Explain why should we implement this feature as much as possible.
- Explain why should we implement this feature as much as possible.
2 changes: 1 addition & 1 deletion .github/SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ coordinate the fix and release process, involving the following steps:

## Comments on this Policy

If you have suggestions on how this process could be improved please submit a pull request.
If you have suggestions on how this process could be improved please submit a pull request.
25 changes: 25 additions & 0 deletions src/commands/misc/avatar.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import type { CommandInteraction } from "discord.js";
import { ApplicationCommandOptionType, User } from "discord.js";
import { Discord, Slash, SlashOption } from "discordx";
import { Category } from "@discordx/utilities";

@Discord()
@Category("Miscellaneous")
export class AvatarCommand {
@Slash({ description: "Get selected user's avatar", name: "avatar" })
async avatar(
@SlashOption({
description: "User to get avatar from",
name: "user",
type: ApplicationCommandOptionType.User,
required: true,
})
user: User,
interaction: CommandInteraction,
): Promise<void> {
await interaction.reply({
content: user.displayAvatarURL({ size: 4096 }),
ephemeral: true,
});
}
}
10 changes: 6 additions & 4 deletions src/commands/misc/help.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,17 @@ import type { DApplicationCommand } from "discordx";
@Category("Miscellaneous")
@SlashGroup({
description: "Shows a list of all commands or info about a specific command.",
name: "help"
name: "help",
})
@SlashGroup("help")
export class HelpCommand {
@Slash({ description: "Show all available commands" })
async all(interaction: CommandInteraction) {
const commands = MetadataStorage.instance.applicationCommandSlashesFlat.map((cmd: DApplicationCommand & ICategory) => {
return { description: cmd.description, name: cmd.name, category: cmd.category };
});
const commands = MetadataStorage.instance.applicationCommandSlashesFlat.map(
(cmd: DApplicationCommand & ICategory) => {
return { description: cmd.description, name: cmd.name, category: cmd.category };
},
);
const categories = new Set(commands.map((c) => c.category));
const pages = Array.from(categories).map((category, idx) => {
const categoryCommands = commands.filter((c) => c.category === category);
Expand Down
6 changes: 4 additions & 2 deletions src/commands/misc/ping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ export class PingCommand {
fetchReply: true,
});

const timeDiff = (sent.createdTimestamp - interaction.createdTimestamp);
await interaction.editReply(`🏓Pong!\nRound-trip latency: ${timeDiff} ms\nWebsocket heartbeat: ${Math.round(bot.ws.ping)} ms`);
const timeDiff = sent.createdTimestamp - interaction.createdTimestamp;
await interaction.editReply(
`🏓Pong!\nRound-trip latency: ${timeDiff} ms\nWebsocket heartbeat: ${Math.round(bot.ws.ping)} ms`,
);
}
}
8 changes: 2 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,7 @@ const BOT_LOG = debuglog("bot");
export const bot = new Client({
botId: CLIENT_ID,
botGuilds: NODE_ENV ? [process.env.GUILD_ID!] : [],
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildVoiceStates,
GatewayIntentBits.GuildMessages
],
intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildVoiceStates, GatewayIntentBits.GuildMessages],
silent: false,
simpleCommand: {
prefix: "mx!",
Expand Down Expand Up @@ -49,4 +45,4 @@ async function main() {
await bot.login(TOKEN);
}

main();
main();
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,6 @@

/* Completeness */
// "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
"skipLibCheck": true /* Skip type checking all .d.ts files. */
"skipLibCheck": true /* Skip type checking all .d.ts files. */
}
}

0 comments on commit 32aa8f7

Please sign in to comment.