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
61
index.ts
61
index.ts
|
@ -1,46 +1,47 @@
|
|||
import { ActivityType, Client, EmbedBuilder, Events, GatewayIntentBits } from "discord.js";
|
||||
import { ActivityType, Client, Events, GatewayIntentBits, REST, Routes } from "discord.js";
|
||||
import user from "./cmd/user";
|
||||
import { db } from "./db";
|
||||
import { formatSize } from "./lib";
|
||||
import { StereoFile } from "./types";
|
||||
|
||||
const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent] });
|
||||
const client = new Client({
|
||||
intents: [
|
||||
GatewayIntentBits.Guilds,
|
||||
GatewayIntentBits.GuildMessages,
|
||||
GatewayIntentBits.MessageContent,
|
||||
|
||||
]
|
||||
});
|
||||
const rest = new REST({ version: "10" }).setToken(process.env.TOKEN);
|
||||
|
||||
client.once(Events.ClientReady, async (c) => {
|
||||
console.log(c.user.tag);
|
||||
await rest.put(
|
||||
Routes.applicationCommands(process.env.CLIENT_ID),
|
||||
{ body: commands.map(([data]) => data) }
|
||||
);
|
||||
|
||||
const files = (await db.all<StereoFile[]>`SELECT * FROM files`).length
|
||||
c.user.setPresence({
|
||||
activities: [{ name: `${files} files uploaded to stereo`, type: ActivityType.Custom }],
|
||||
status: "dnd"
|
||||
});
|
||||
|
||||
console.log(c.user.tag);
|
||||
});
|
||||
|
||||
client.on(Events.MessageCreate, async (message) => {
|
||||
if (message.author.bot) return;
|
||||
if (
|
||||
client.user &&
|
||||
message.mentions.has(client.user) &&
|
||||
!message.mentions.everyone
|
||||
) {
|
||||
let files = await db.all<StereoFile[]>`SELECT * FROM files WHERE owner = ${message.author.id}`;
|
||||
let totalSize = files.reduce((a, b) => a + b.size, 0);
|
||||
const commands = [
|
||||
user
|
||||
]
|
||||
|
||||
const embed = new EmbedBuilder()
|
||||
.setColor(0xff264e)
|
||||
.setAuthor({
|
||||
name: `${message.author.globalName || "user"} on stereo`,
|
||||
iconURL: message.author.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 message.reply({ embeds: [embed] });
|
||||
}
|
||||
client.on(Events.InteractionCreate, async interaction => {
|
||||
if (!interaction.isChatInputCommand()) return;
|
||||
const cmd = commands.find(([data]) => data.name === interaction.commandName);
|
||||
if (!cmd) return;
|
||||
try {
|
||||
await cmd[1](interaction);
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
await interaction.reply({ content: "there was an error executing this command", ephemeral: true });
|
||||
}
|
||||
});
|
||||
|
||||
client.login(process.env.TOKEN).catch((err) => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue