File size: 2,254 Bytes
6466b9d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
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] });
        }
	}
};