add user command to retrieve user information and upload stats
This commit is contained in:
parent
2f57cb7d39
commit
5cfcb3ba0c
4 changed files with 82 additions and 31 deletions
46
cmd/user.ts
Normal file
46
cmd/user.ts
Normal file
|
@ -0,0 +1,46 @@
|
|||
// commands/overview.ts
|
||||
import { ChatInputCommandInteraction, EmbedBuilder, MessageFlags, SlashCommandBuilder } from "discord.js";
|
||||
import { db } from "../db";
|
||||
import { formatSize } from "../lib";
|
||||
import { StereoFile } from "../types";
|
||||
|
||||
export const data = new SlashCommandBuilder()
|
||||
.setName("user")
|
||||
.addUserOption(option => option.setName("user").setDescription("user to look up").setRequired(false))
|
||||
.setDescription("get information about a user (or yourself) on stereo");
|
||||
|
||||
export const execute = async (interaction: ChatInputCommandInteraction) => {
|
||||
const user = interaction.options.getUser("user") || interaction.user;
|
||||
if (!user) {
|
||||
await interaction.reply({ content: "couldn't find user", flags: MessageFlags.Ephemeral });
|
||||
return;
|
||||
}
|
||||
|
||||
const id = await db.get<{ id: string }>`SELECT id FROM users WHERE id = ${user.id}`;
|
||||
if (!id) {
|
||||
await interaction.reply({ content: "this user doesn't have a stereo account", flags: MessageFlags.Ephemeral });
|
||||
return;
|
||||
}
|
||||
|
||||
const files = await db.all<StereoFile[]>`SELECT * FROM files WHERE owner = ${user.id}`;
|
||||
const totalSize = files.reduce((a, b) => a + b.size, 0);
|
||||
|
||||
const embed = new EmbedBuilder()
|
||||
.setColor(0xff264e)
|
||||
.setAuthor({
|
||||
name: `${user.globalName || "user"} on stereo`,
|
||||
iconURL: user.avatarURL({ size: 512 }) || ""
|
||||
})
|
||||
.setDescription("Here's your overview:")
|
||||
.addFields(
|
||||
{ name: "Uploads", value: `${files.length} files`, inline: true },
|
||||
{ name: "Uploaded", value: `${formatSize(totalSize)} / 15 GB`, inline: true },
|
||||
{ name: "Plan", value: `Free`, inline: true }
|
||||
)
|
||||
.setFooter({ text: "powered by stereo" })
|
||||
.setTimestamp();
|
||||
|
||||
await interaction.reply({ embeds: [embed] });
|
||||
}
|
||||
|
||||
export default [data, execute] as const;
|
Loading…
Add table
Add a link
Reference in a new issue