File size: 1,697 Bytes
c35213b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5fb7488
c35213b
 
 
 
 
5fb7488
 
c35213b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
const { createEmbed } = require('../utils/embeds');
const { Colors } = require('../config');
const { stmts } = require('../database');
const fetch = require('node-fetch');

/**
 * usage: deletedrop <id>
 */
module.exports = {
    async execute(client, message, args) {
        if (args.length < 1) {
            return message.reply({ content: '❌ Usage: `deletedrop <id>`' });
        }

        const id = parseInt(args[0]);
        if (isNaN(id)) return message.reply({ content: '❌ Invalid Drop ID. Must be a number.' });

        const drop = await stmts.getWebDrop(id);
        if (!drop) {
            return message.reply({ content: `❌ No drop found in database with ID: **${id}**` });
        }

        try {
            // 1. Delete from Supabase
            await stmts.deleteWebDrop(id);

            // 2. Send DELETE request to Website Backend API
            const WEBSITE_API = process.env.WEBSITE_API_URL || 'http://localhost:3000/api/drops';
            
            try {
                // Mock request for now
                await fetch(`${WEBSITE_API}/${id}`, {
                    method: 'DELETE',
                }).catch(() => {});
            } catch (e) {}

            await message.reply({
                embeds: [createEmbed({
                    title: 'πŸ—‘οΈ Drop Deleted',
                    description: `Successfully deleted Drop **#${id}** (${drop.title}) from the website backend.`,
                    color: Colors.SUCCESS
                })]
            });

        } catch (err) {
            console.error('[Delete Drop Error]', err);
            await message.reply({ content: `❌ Error deleting drop: ${err.message}` });
        }
    }
};