plsgivemeachane
EZGG
6466b9d
import { PrismaClient } from '@prisma/client'
import { Collection, CommandInteraction, SlashCommandBuilder, EmbedBuilder } from 'discord.js';
const prisma = new PrismaClient()
declare module "discord.js" {
export interface Client {
commands: Collection<any, any>,
api_key: Collection<string, string>
}
}
module.exports = {
data: new SlashCommandBuilder()
.setName('backup')
.setDescription('Get all listened Backups'),
async execute(interaction: CommandInteraction) {
// await interaction.reply('Pong!');
// get server id
// const serverId = interaction.guild?.id;
// interaction.client.api_key = interaction.options.get('api_key')?.value as string;
const serverId = interaction.guild?.id as string;
const api = interaction.client.api_key.get(serverId)
// Query the database
const record = await prisma.storage.findMany({
where: {
API_KEY: api
}
})
const api_record = await prisma.aPIList.findUnique({
where: {
API_KEY: api
}
})
if(!record){
await interaction.reply({
content: 'Dont have any backups!'
});
} else {
// only take last 10 records
const lastTen = record.slice(-10);
const fields = lastTen.map((r) => (
{ name: r.file_name + " -----------> " + new Date(r.created_at).toLocaleString(), value: "https://leeminwaan-ufsuploadfile.hf.space/file?filename=" + r.file_name}
));
const exampleEmbed = new EmbedBuilder()
.setColor(0x0099FF)
.setTitle('Backup records for server: ' + api_record?.USER)
.setAuthor({ name: 'UFS Drive backups services', iconURL: 'https://www.ufsdrive.com/logo.png'})
.setDescription('World backups records')
.setThumbnail('https://www.ufsdrive.com/logo.png')
.addFields(
{ name: '\u200B', value: '\u200B' },
)
.addFields(
fields
)
await interaction.reply({ embeds: [exampleEmbed] });
}
}
};