Download src/events/messageCreate.js from APRKDEV/wsb-bot: direct link, hf CLI and curl.
- Browser
- Download file 7.74 kB
-
https://huggingface.co/spaces/APRKDEV/wsb-bot/resolve/c8f3880098432483b23491dd763585274d00f8c8/src/events/messageCreate.js
- Command line
-
hf download hf://spaces/APRKDEV/wsb-bot@c8f3880098432483b23491dd763585274d00f8c8/src/events/messageCreate.js
-
curl -L -o messageCreate.js https://huggingface.co/spaces/APRKDEV/wsb-bot/resolve/c8f3880098432483b23491dd763585274d00f8c8/src/events/messageCreate.js
7.74 kB
| const { ChannelType } = require('discord.js'); | |
| const { errorEmbed, infoEmbed, successEmbed, createEmbed } = require('../utils/embeds'); | |
| const { logCommand } = require('../systems/logger'); | |
| const { startDropSession, hasSession, getPrompt, handleDropMessage, canDrop } = require('../systems/drops'); | |
| const { stmts } = require('../database'); | |
| const { Colors } = require('../config'); | |
| // Import command handlers | |
| const setup = require('../commands/setup'); | |
| const createRoles = require('../commands/createRoles'); | |
| const createChannels = require('../commands/createChannels'); | |
| const backupLayout = require('../commands/backupLayout'); | |
| const shutdown = require('../commands/shutdown'); | |
| const ticketStats = require('../commands/ticketStats'); | |
| const permissionAudit = require('../commands/permissionAudit'); | |
| const postRules = require('../commands/postRules'); | |
| const postDisclaimer = require('../commands/postDisclaimer'); | |
| const applyUpdates = require('../commands/applyUpdates'); | |
| const fixPings = require('../commands/fixPings'); | |
| const clearDrops = require('../commands/clearDrops'); | |
| const OWNER_ID = process.env.OWNER_ID; | |
| // Owner-only command registry | |
| const commands = { | |
| 'setup server': setup, | |
| 'create roles': createRoles, | |
| 'create channels': createChannels, | |
| 'backup layout': backupLayout, | |
| 'shutdown bot': shutdown, | |
| 'ticket stats': ticketStats, | |
| 'permission audit': permissionAudit, | |
| 'post rules': postRules, | |
| 'post disclaimer': postDisclaimer, | |
| 'apply updates': applyUpdates, | |
| 'fix pings': fixPings, | |
| }; | |
| module.exports = { | |
| name: 'messageCreate', | |
| async execute(client, message) { | |
| if (message.author.bot) return; | |
| if (message.channel.type !== ChannelType.DM) return; | |
| const userId = message.author.id; | |
| const content = message.content.trim().toLowerCase(); | |
| // ββ Handle active drop session (owner OR whitelisted) ββ | |
| if (hasSession(userId)) { | |
| try { | |
| const handled = await handleDropMessage(message); | |
| if (handled) return; | |
| } catch (err) { | |
| console.error('[Drop Error]', err); | |
| await message.reply({ content: `β Drop error: ${err.message}` }).catch(() => { }); | |
| return; | |
| } | |
| } | |
| // ββ Whitelisted user: only allow "drop" ββ | |
| if (userId !== OWNER_ID) { | |
| if (content === 'drop') { | |
| const check = canDrop(userId); | |
| if (!check.allowed) { | |
| if (check.reason === 'not_whitelisted') { | |
| return; // Silently ignore non-whitelisted users | |
| } | |
| // Rate limited | |
| return message.reply({ | |
| embeds: [createEmbed({ | |
| title: 'β³ Drop Cooldown', | |
| description: `You've used all **${check.limit} drops** in the last 24 hours.\n\n> Resets in **${check.resetIn}**`, | |
| color: Colors.WARNING, | |
| })], | |
| }); | |
| } | |
| const session = startDropSession(userId); | |
| await message.reply({ | |
| ...getPrompt(session), | |
| content: `π¦ **Drop ${check.limit - check.remaining + 1}/${check.limit} for today**`, | |
| }); | |
| return; | |
| } | |
| return; // Whitelisted users can only use "drop" | |
| } | |
| // ββ Owner-only commands below ββββββββββββββββββββββββββ | |
| // Drop (no rate limit for owner) | |
| if (content === 'drop') { | |
| await logCommand(client, 'drop'); | |
| const session = startDropSession(userId); | |
| await message.reply(getPrompt(session)); | |
| return; | |
| } | |
| // Whitelist management | |
| if (content.startsWith('whitelist ') && !content.startsWith('whitelist <')) { | |
| const args = content.split(' ').slice(1); | |
| const targetId = args[0]?.trim(); | |
| const limit = parseInt(args[1]) || 3; | |
| if (!targetId || !/^\d{17,20}$/.test(targetId)) { | |
| return message.reply({ embeds: [errorEmbed('Invalid ID', 'Usage: `whitelist <user_id> [limit]`\nExample: `whitelist 123456789 5`')] }); | |
| } | |
| stmts.addWhitelist.run(targetId, limit, userId); | |
| const user = await client.users.fetch(targetId).catch(() => null); | |
| const name = user ? `**${user.tag}**` : `ID \`${targetId}\``; | |
| return message.reply({ embeds: [successEmbed('β Whitelisted', `${name} can now use \`drop\` (**${limit}** per day)`)] }); | |
| } | |
| if (content.startsWith('unwhitelist ')) { | |
| const targetId = content.split(' ')[1]?.trim(); | |
| if (!targetId) return message.reply({ embeds: [errorEmbed('Invalid ID', 'Usage: `unwhitelist <user_id>`')] }); | |
| stmts.removeWhitelist.run(targetId); | |
| return message.reply({ embeds: [successEmbed('β Removed', `User \`${targetId}\` removed from whitelist`)] }); | |
| } | |
| // Clear Drops | |
| if (content.startsWith('clear ')) { | |
| const args = content.split(' ').slice(1); | |
| return clearDrops.execute(client, message, args); | |
| } | |
| if (content === 'whitelist') { | |
| const all = stmts.getAllWhitelist.all(); | |
| if (all.length === 0) { | |
| return message.reply({ embeds: [infoEmbed('Whitelist', 'No users whitelisted.\n\nUse `whitelist <user_id>` to add.')] }); | |
| } | |
| const lines = []; | |
| for (const w of all) { | |
| const user = await client.users.fetch(w.user_id).catch(() => null); | |
| const name = user ? user.tag : 'Unknown'; | |
| const drops = stmts.getDropCount24h.get(w.user_id); | |
| lines.push(`β’ **${name}** (\`${w.user_id}\`) β ${drops.count}/${w.max_drops} drops today`); | |
| } | |
| return message.reply({ embeds: [infoEmbed('π Whitelist', lines.join('\n'))] }); | |
| } | |
| // Show help | |
| if (content === 'help') { | |
| const allCommands = [...Object.keys(commands), 'drop', 'whitelist', 'whitelist <id> [limit]', 'unwhitelist <id>', 'clear <channel_id>']; | |
| const embed = infoEmbed('WSB Commands', [ | |
| 'All commands are **DM-only** and **Owner-only**.\n', | |
| ...allCommands.map(cmd => `\`${cmd}\``), | |
| ].join('\n')); | |
| return message.reply({ embeds: [embed] }); | |
| } | |
| // Find matching command | |
| const handler = commands[content]; | |
| if (!handler) { | |
| if (content.startsWith('setup') || content.startsWith('create') || | |
| content.startsWith('backup') || content.startsWith('shutdown') || | |
| content.startsWith('ticket') || content.startsWith('permission') || | |
| content.startsWith('post') || content.startsWith('drop') || | |
| content.startsWith('apply') || content.startsWith('fix') || | |
| content.startsWith('clear')) { | |
| return message.reply({ embeds: [errorEmbed('Unknown Command', `Did you mean one of these?\n${[...Object.keys(commands), 'drop', 'clear <channel_id>'].map(c => `\`${c}\``).join('\n')}`)] }); | |
| } | |
| return; | |
| } | |
| try { | |
| await logCommand(client, content); | |
| await handler.execute(client, message); | |
| } catch (err) { | |
| console.error(`[Command Error] ${content}:`, err); | |
| await message.reply({ embeds: [errorEmbed('Error', `Command failed: \`${err.message}\``)] }).catch(() => { }); | |
| } | |
| }, | |
| }; | |