Small fix
This commit is contained in:
@@ -15,11 +15,9 @@ module.exports = {
|
||||
const dbClient = await connectToDatabase();
|
||||
const db = dbClient.db('discord');
|
||||
const collection = db.collection('currency');
|
||||
|
||||
const target = interaction.options.getUser('user') ?? interaction.user;
|
||||
const targetData = await collection.findOne({ userID: target.id });
|
||||
const balance = targetData?.balance ?? 0;
|
||||
|
||||
return interaction.reply({
|
||||
content: `${target.tag} has **${balance}** coins.`,
|
||||
});
|
||||
|
||||
@@ -9,12 +9,10 @@ const formatDuration = (ms) => {
|
||||
const hours = Math.floor(totalSeconds / 3600);
|
||||
const minutes = Math.floor((totalSeconds % 3600) / 60);
|
||||
const seconds = totalSeconds % 60;
|
||||
|
||||
const parts = [];
|
||||
if (hours) parts.push(`${hours}h`);
|
||||
if (minutes) parts.push(`${minutes}m`);
|
||||
if (!hours && !minutes) parts.push(`${seconds}s`);
|
||||
|
||||
return parts.join(' ');
|
||||
};
|
||||
|
||||
@@ -28,11 +26,9 @@ module.exports = {
|
||||
const db = dbClient.db('discord');
|
||||
const collection = db.collection('currency');
|
||||
const now = new Date();
|
||||
|
||||
const userId = interaction.user.id;
|
||||
const userData = await collection.findOne({ userID: userId });
|
||||
const lastClaim = userData?.lastClaimedAt ? new Date(userData.lastClaimedAt) : null;
|
||||
|
||||
if (lastClaim) {
|
||||
const elapsed = now - lastClaim;
|
||||
if (elapsed < COOLDOWN_MS) {
|
||||
@@ -43,7 +39,6 @@ module.exports = {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
await collection.updateOne(
|
||||
{ userID: userId },
|
||||
{
|
||||
@@ -52,7 +47,6 @@ module.exports = {
|
||||
},
|
||||
{ upsert: true }
|
||||
);
|
||||
|
||||
return interaction.reply({
|
||||
content: `You earned **${REWARD_AMOUNT}** coins! Come back tomorrow for more.`,
|
||||
});
|
||||
|
||||
@@ -22,23 +22,19 @@ module.exports = {
|
||||
const dbClient = await connectToDatabase();
|
||||
const target = interaction.options.getUser('target');
|
||||
const amount = interaction.options.getInteger('amount');
|
||||
|
||||
if (target.bot) {
|
||||
return interaction.reply({
|
||||
content: 'You cannot grant coins to bot accounts.',
|
||||
ephemeral: true,
|
||||
});
|
||||
}
|
||||
|
||||
const db = dbClient.db('discord');
|
||||
const collection = db.collection('currency');
|
||||
|
||||
await collection.updateOne(
|
||||
{ userID: target.id },
|
||||
{ $inc: { balance: amount } },
|
||||
{ upsert: true }
|
||||
);
|
||||
|
||||
return interaction.reply({
|
||||
content: `You granted **${amount}** coins to ${target.tag}.`,
|
||||
});
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// exampleCommand.js
|
||||
const { SlashCommandBuilder } = require('discord.js');
|
||||
const { connectToDatabase } = require('../../db.js');
|
||||
|
||||
@@ -15,14 +14,9 @@ module.exports = {
|
||||
async execute(interaction) {
|
||||
const dbClient = await connectToDatabase();
|
||||
const message = interaction.options.getString('message');
|
||||
|
||||
// Choose a DB + Collection
|
||||
const db = dbClient.db('discord');
|
||||
const collection = db.collection('test');
|
||||
|
||||
// Example: Insert something
|
||||
await collection.insertOne({ userId: interaction.user.id, message: message });
|
||||
|
||||
await interaction.reply('Successfully inserted your data into MongoDB.');
|
||||
},
|
||||
};
|
||||
|
||||
@@ -30,7 +30,6 @@ module.exports = {
|
||||
ephemeral: true,
|
||||
});
|
||||
}
|
||||
|
||||
await member.kick(reason);
|
||||
await recordModerationAction({
|
||||
guildId: interaction.guildId,
|
||||
@@ -40,7 +39,6 @@ module.exports = {
|
||||
reason,
|
||||
metadata: {},
|
||||
});
|
||||
|
||||
await interaction.reply(`Kicked ${user.tag} for: ${reason}`);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
|
||||
+18
-7
@@ -1,13 +1,10 @@
|
||||
const crypto = require('node:crypto');
|
||||
const fs = require('node:fs');
|
||||
const path = require('node:path');
|
||||
|
||||
const axios = require('axios');
|
||||
const express = require('express');
|
||||
|
||||
const {addWarning, getWarnings} = require('./services/warnings');
|
||||
const {getGuildPermissions, updateGuildPermissions} = require('./services/permissions');
|
||||
|
||||
const DEFAULT_SESSION_TTL_MS = 24 * 60 * 60 * 1000;
|
||||
const PERMISSION_BITS = {
|
||||
ADMINISTRATOR: 0x8n,
|
||||
@@ -50,6 +47,14 @@ const SESSION_TTL_MS = Number.parseInt(
|
||||
10,
|
||||
);
|
||||
|
||||
console.log('[oauth config]', {
|
||||
DISCORD_CLIENT_ID_present: Boolean(DISCORD_CLIENT_ID && String(DISCORD_CLIENT_ID).trim()),
|
||||
DISCORD_CLIENT_SECRET_present: Boolean(DISCORD_CLIENT_SECRET && String(DISCORD_CLIENT_SECRET).trim()),
|
||||
DISCORD_REDIRECT_URI: DISCORD_REDIRECT_URI || null,
|
||||
configFilePath: path.join(__dirname, 'config.json'),
|
||||
configFileExists: fs.existsSync(path.join(__dirname, 'config.json')),
|
||||
});
|
||||
|
||||
const DISCORD_API_BASE = 'https://discord.com/api';
|
||||
|
||||
const sessionStore = new Map();
|
||||
@@ -299,7 +304,6 @@ const createDashboardApp = () => {
|
||||
tokenType: tokenData.token_type,
|
||||
scope: tokenData.scope,
|
||||
user,
|
||||
expiresAt,
|
||||
});
|
||||
|
||||
setCookie(res, 'dashboard_session', sessionId, {
|
||||
@@ -320,7 +324,16 @@ const createDashboardApp = () => {
|
||||
|
||||
return res.status(200).json({user});
|
||||
} catch (error) {
|
||||
return res.status(502).json({ error: 'Failed to authenticate with Discord' });
|
||||
console.error('Discord OAuth failed', {
|
||||
message: error.message,
|
||||
status: error.response?.status,
|
||||
data: error.response?.data,
|
||||
});
|
||||
|
||||
return res.status(502).json({
|
||||
error: 'Failed to authenticate with Discord',
|
||||
details: error.response?.data || error.message,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
@@ -411,7 +424,6 @@ const createDashboardApp = () => {
|
||||
if (!reason) {
|
||||
return res.status(400).json({error: 'Reason is required'});
|
||||
}
|
||||
|
||||
try {
|
||||
const result = await addWarning({
|
||||
guildId: req.params.guildId,
|
||||
@@ -425,7 +437,6 @@ const createDashboardApp = () => {
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
return app;
|
||||
};
|
||||
|
||||
|
||||
@@ -5,7 +5,6 @@ let dbClient;
|
||||
|
||||
async function connectToDatabase() {
|
||||
if (!dbClient) {
|
||||
// Create a new MongoClient only once
|
||||
dbClient = new MongoClient(mongodb, {
|
||||
serverApi: {
|
||||
version: ServerApiVersion.v1,
|
||||
@@ -13,15 +12,11 @@ async function connectToDatabase() {
|
||||
deprecationErrors: true,
|
||||
}
|
||||
});
|
||||
|
||||
await dbClient.connect();
|
||||
console.log("Connected to MongoDB!");
|
||||
|
||||
await dbClient.db("admin").command({ping: 1});
|
||||
console.log("Pinged your deployment. You successfully connected to MongoDB!");
|
||||
}
|
||||
|
||||
// Return the existing connection if already connected
|
||||
return dbClient;
|
||||
}
|
||||
|
||||
|
||||
@@ -5,14 +5,11 @@ module.exports = {
|
||||
name: Events.InteractionCreate,
|
||||
async execute(interaction) {
|
||||
if (!interaction.isChatInputCommand()) return;
|
||||
|
||||
const command = interaction.client.commands.get(interaction.commandName);
|
||||
|
||||
if (!command) {
|
||||
console.error(`No command matching ${interaction.commandName} was found.`);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const allowed = await isCommandAllowed({
|
||||
guildId: interaction.guildId,
|
||||
@@ -21,7 +18,6 @@ module.exports = {
|
||||
commandName: interaction.commandName,
|
||||
permissionGroup: command.permissionGroup,
|
||||
});
|
||||
|
||||
if (!allowed) {
|
||||
await interaction.reply({
|
||||
content: 'You do not have permission to use this command.',
|
||||
@@ -29,14 +25,19 @@ module.exports = {
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
await command.execute(interaction);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
if (interaction.replied || interaction.deferred) {
|
||||
await interaction.followUp({ content: 'There was an error while executing this command!', flags: MessageFlags.Ephemeral });
|
||||
await interaction.followUp({
|
||||
content: 'There was an error while executing this command!',
|
||||
flags: MessageFlags.Ephemeral
|
||||
});
|
||||
} else {
|
||||
await interaction.reply({ content: 'There was an error while executing this command!', flags: MessageFlags.Ephemeral });
|
||||
await interaction.reply({
|
||||
content: 'There was an error while executing this command!',
|
||||
flags: MessageFlags.Ephemeral
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -10,8 +10,6 @@ module.exports = {
|
||||
const tempBanCollection = db.collection('tempban');
|
||||
const scheduledBanIds = new Set();
|
||||
let pollingInterval = null;
|
||||
|
||||
// 2) Define a function to schedule unbans
|
||||
async function scheduleUnban(banData) {
|
||||
const banId = banData?._id?.toString();
|
||||
if (banId && scheduledBanIds.has(banId)) {
|
||||
@@ -54,7 +52,6 @@ module.exports = {
|
||||
if (pollingInterval) {
|
||||
return;
|
||||
}
|
||||
console.warn('Change streams unavailable; falling back to polling for temp bans.');
|
||||
pollingInterval = setInterval(() => {
|
||||
loadAndScheduleBans().catch((err) => {
|
||||
console.error('Error polling temp bans:', err);
|
||||
|
||||
@@ -3,13 +3,12 @@ const { Client, Collection, GatewayIntentBits } = require('discord.js');
|
||||
const { token } = require('./config.json');
|
||||
const { loadCommandModules } = require('./loaders/commands');
|
||||
const { loadEventModules } = require('./loaders/events');
|
||||
|
||||
const client = new Client({ intents: [GatewayIntentBits.Guilds] });
|
||||
|
||||
// Retrieves commands from the command folder
|
||||
client.commands = new Collection();
|
||||
const commandsPath = path.join(__dirname, 'commands');
|
||||
const { commands, invalidCommands } = loadCommandModules(commandsPath);
|
||||
const eventsPath = path.join(__dirname, 'events');
|
||||
const eventModules = loadEventModules(eventsPath);
|
||||
|
||||
for (const command of commands) {
|
||||
client.commands.set(command.data.name, command);
|
||||
@@ -19,10 +18,6 @@ for (const filePath of invalidCommands) {
|
||||
console.log(`[WARNING] The command at ${filePath} is missing a required "data" or "execute" property.`);
|
||||
}
|
||||
|
||||
// Retrieves events from the events folder
|
||||
const eventsPath = path.join(__dirname, 'events');
|
||||
const eventModules = loadEventModules(eventsPath);
|
||||
|
||||
for (const { event } of eventModules) {
|
||||
if (event.once) {
|
||||
client.once(event.name, (...args) => event.execute(...args));
|
||||
|
||||
@@ -11,7 +11,6 @@ const getEventFilePaths = (eventsPath) =>
|
||||
|
||||
const loadEventModules = (eventsPath) => {
|
||||
const eventFiles = getEventFilePaths(eventsPath);
|
||||
|
||||
return eventFiles.map((filePath) => ({
|
||||
filePath,
|
||||
event: require(filePath),
|
||||
|
||||
@@ -15,7 +15,6 @@ const DEFAULT_GUILD_SETTINGS = {
|
||||
const normalizeGuildSettings = (settings = {}) => {
|
||||
const moderation = settings.moderation ?? {};
|
||||
const strikeThresholds = moderation.strikeThresholds ?? {};
|
||||
|
||||
return {
|
||||
...DEFAULT_GUILD_SETTINGS,
|
||||
...settings,
|
||||
@@ -34,12 +33,10 @@ const getGuildSettings = async (guildId) => {
|
||||
if (!guildId) {
|
||||
return normalizeGuildSettings();
|
||||
}
|
||||
|
||||
const dbClient = await connectToDatabase();
|
||||
const db = dbClient.db('discord');
|
||||
const collection = db.collection('guild_settings');
|
||||
const settings = await collection.findOne({ guildId });
|
||||
|
||||
return normalizeGuildSettings(settings);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user