wsb-bott / src /commands /editDrop.js
APRKDEV's picture
Upload 43 files
e5c9966 verified
const { Octokit } = require('@octokit/rest');
const { createEmbed } = require('../utils/embeds');
const { Colors } = require('../config');
const { stmts } = require('../database');
const fetch = require('node-fetch');
/**
* usage: editdrop <id> <property> <new_value>
* properties: title, description, status
*/
module.exports = {
async execute(client, message, args) {
if (args.length < 3) {
return message.reply({ content: '❌ Usage: `editdrop <id> <title|description|status> <new value>`' });
}
const id = parseInt(args[0]);
const property = args[1].toLowerCase();
const newValue = args.slice(2).join(' ');
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}**` });
}
const validProps = ['title', 'description', 'status'];
if (!validProps.includes(property)) {
return message.reply({ content: `❌ Invalid property. Use: ${validProps.join(', ')}` });
}
try {
// 1. Update Supabase
const { db } = require('../database');
await db.from('web_drops').update({ [property]: newValue }).eq('id', id);
// 2. Send update 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: 'PATCH',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ [property]: newValue })
}).catch(() => {});
} catch (e) {}
await message.reply({
embeds: [createEmbed({
title: 'βœ… Drop Updated',
description: `Successfully updated Drop **#${id}**.\n\n**${property}** is now:\n> ${newValue}`,
color: Colors.SUCCESS
})]
});
} catch (err) {
console.error('[Edit Drop Error]', err);
await message.reply({ content: `❌ Error updating drop: ${err.message}` });
}
}
};