| const { Octokit } = require('@octokit/rest'); |
| const { createEmbed } = require('../utils/embeds'); |
| const { Colors } = require('../config'); |
| const { stmts } = require('../database'); |
| const fetch = require('node-fetch'); |
|
|
| |
| |
| |
| |
| 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 { |
| |
| const { db } = require('../database'); |
| await db.from('web_drops').update({ [property]: newValue }).eq('id', id); |
|
|
| |
| const WEBSITE_API = process.env.WEBSITE_API_URL || 'http://localhost:3000/api/drops'; |
| |
| try { |
| |
| 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}` }); |
| } |
| } |
| }; |
|
|