aboutsummaryrefslogtreecommitdiff
path: root/bot
diff options
context:
space:
mode:
authorAndrew Lee <andrew@alee14.me>2025-03-25 14:13:06 -0400
committerAndrew Lee <andrew@alee14.me>2025-03-25 14:13:06 -0400
commit1c12d378d66b92b1674acd17640f2bac752da289 (patch)
treebc8a1ef5047be1ed2400f2204a0222a840375851 /bot
parentad768e2b25b58d62a44aa2daeb1429a651d488e5 (diff)
downloadAleeBot-1c12d378d66b92b1674acd17640f2bac752da289.tar.gz
AleeBot-1c12d378d66b92b1674acd17640f2bac752da289.tar.bz2
AleeBot-1c12d378d66b92b1674acd17640f2bac752da289.zip
Converted public dashboard to admin dashboard; Made API have a consistent output message
Diffstat (limited to 'bot')
-rw-r--r--bot/src/api/routes/auth.js14
-rw-r--r--bot/src/api/routes/quotes.js18
-rw-r--r--bot/src/api/routes/settings.js10
-rw-r--r--bot/src/api/server.js4
-rw-r--r--bot/src/commands/settings.js8
5 files changed, 28 insertions, 26 deletions
diff --git a/bot/src/api/routes/auth.js b/bot/src/api/routes/auth.js
index 224a2d1..81a3e40 100644
--- a/bot/src/api/routes/auth.js
+++ b/bot/src/api/routes/auth.js
@@ -6,7 +6,7 @@ import dotenv from 'dotenv';
dotenv.config();
// Check if required environment variables are set
-const requiredEnvVars = ['JWT_SECRET', 'AUTH_USERNAME', 'AUTH_PASSWORD_HASH'];
+const requiredEnvVars = ['JWT_SECRET', 'API_USERNAME', 'API_PASSWORD_HASH'];
const missingVars = requiredEnvVars.filter(varName => !process.env[varName]);
if (missingVars.length > 0) {
console.error(`Missing required environment variables: ${missingVars.join(', ')}`);
@@ -22,18 +22,18 @@ export function authRouter() {
const { username, password } = req.body;
if (!username || !password) {
- return res.status(400).json({ error: 'Username and password are required' });
+ return res.status(400).json({ message: 'Username and password are required' });
}
// Check against environment variables
if (username !== process.env.API_USERNAME) {
- return res.status(401).json({ error: 'Invalid credentials' });
+ return res.status(401).json({ message: 'Invalid credentials' });
}
// Verify password
const isPasswordValid = await bcrypt.compare(password, process.env.API_PASSWORD_HASH);
if (!isPasswordValid) {
- return res.status(401).json({ error: 'Invalid credentials' });
+ return res.status(401).json({ message: 'Invalid credentials' });
}
// Generate JWT token
@@ -46,7 +46,7 @@ export function authRouter() {
res.json({ token });
} catch (error) {
console.error('Login error:', error);
- res.status(500).json({ error: 'Internal server error' });
+ res.status(500).json({ message: 'Internal server error' });
}
});
@@ -58,7 +58,7 @@ export function verifyToken(req, res, next) {
const authHeader = req.headers.authorization;
if (!authHeader || !authHeader.startsWith('Bearer ')) {
- return res.status(401).json({ error: 'No token provided' });
+ return res.status(401).json({ message: 'Unauthorized' });
}
const token = authHeader.split(' ')[1];
@@ -68,6 +68,6 @@ export function verifyToken(req, res, next) {
req.user = decoded;
next();
} catch {
- return res.status(403).json({ error: 'Invalid or expired token' });
+ return res.status(403).json({ message: 'Invalid or expired token' });
}
}
diff --git a/bot/src/api/routes/quotes.js b/bot/src/api/routes/quotes.js
index 7f9f255..f362d7e 100644
--- a/bot/src/api/routes/quotes.js
+++ b/bot/src/api/routes/quotes.js
@@ -10,7 +10,7 @@ quoteRouter.get('/quotes/pending', verifyToken, async (req, res) => {
res.json(quotes);
} catch (error) {
console.error('Error fetching quotes:', error);
- res.status(500).send('Internal Server Error');
+ res.status(500).send({ message: 'Internal Server Error' });
}
});
@@ -24,10 +24,10 @@ quoteRouter.post('/quotes/add', verifyToken, async (req, res) => {
year: year,
submitter: submitterID
});
- res.status(200).send('Added a new quote');
+ res.status(200).send({ message: 'Added a new quote' });
} catch (error) {
console.error('Something went wrong:', error);
- res.status(500).send('Internal Server Error');
+ res.status(500).send({ message: 'Internal Server Error' });
}
});
@@ -44,13 +44,13 @@ quoteRouter.post('/quotes/approve', verifyToken, async (req, res) => {
submitter: quote.submitterID
});
await pendingQuote.destroy({ where: { id } });
- res.status(200).send('Quote approved');
+ res.status(200).send({ message: 'Quote approved' });
} else {
- res.status(404).send('Quote not found');
+ res.status(404).send({ message: 'Quote not found' });
}
} catch (error) {
console.error('Error approving quote:', error);
- res.status(500).send('Internal Server Error');
+ res.status(500).send({ message: 'Internal Server Error' });
}
});
@@ -60,12 +60,12 @@ quoteRouter.post('/quotes/reject', verifyToken, async (req, res) => {
const quote = await pendingQuote.findByPk(id);
if (quote) {
await pendingQuote.destroy({ where: { id } });
- res.status(200).send('Quote rejected');
+ res.status(200).send({ message: 'Quote rejected' });
} else {
- res.status(404).send('Quote not found');
+ res.status(404).send({ message: 'Quote not found' });
}
} catch (error) {
console.error('Error rejecting quote:', error);
- res.status(500).send('Internal Server Error');
+ res.status(500).send({ message: 'Internal Server Error' });
}
});
diff --git a/bot/src/api/routes/settings.js b/bot/src/api/routes/settings.js
index bdef633..794d302 100644
--- a/bot/src/api/routes/settings.js
+++ b/bot/src/api/routes/settings.js
@@ -6,7 +6,7 @@ import { verifyToken } from './auth.js';
export function settingsRouter(client) {
const router = Router();
- router.get('/settings/guild/:id', verifyToken, async (req, res) => {
+ router.get('/settings/guilds/:id', verifyToken, async (req, res) => {
try {
const settings = await guildSettings.findOne({ where: { guildID: req.params.id } });
@@ -38,11 +38,11 @@ export function settingsRouter(client) {
});
} catch (e) {
console.error('Error fetching settings:', e);
- res.status(500).send('Internal Server Error');
+ res.status(500).send({ message: 'Internal Server Error' });
}
});
- router.post('/settings/guild/:id', verifyToken, async (req, res) => {
+ router.post('/settings/guilds/:id', verifyToken, async (req, res) => {
try {
const guildID = req.params.id;
const { ...newSettings } = req.body;
@@ -51,11 +51,11 @@ export function settingsRouter(client) {
const updatedSettings = await guildSettings.findOne({ where: { guildID: guildID } });
res.json(updatedSettings);
} else {
- res.status(404).send('Settings not found');
+ res.status(404).send({ message: 'Settings not found' });
}
} catch (e) {
console.error('Error updating settings:', e);
- res.status(500).send('Internal Server Error');
+ res.status(500).send({ message: 'Internal Server Error' });
}
});
diff --git a/bot/src/api/server.js b/bot/src/api/server.js
index 9ad2026..0a06523 100644
--- a/bot/src/api/server.js
+++ b/bot/src/api/server.js
@@ -21,8 +21,8 @@ export const apiServer = (client) => {
app.get('/api/version', (req, res) => {
const { version } = JSON.parse(readFileSync('./package.json', 'utf-8'));
res.json({
- api_version: '1.0',
- ab_version: version
+ ab_version: version,
+ api_version: '1.1'
});
});
diff --git a/bot/src/commands/settings.js b/bot/src/commands/settings.js
index 5deb371..cb06c99 100644
--- a/bot/src/commands/settings.js
+++ b/bot/src/commands/settings.js
@@ -6,6 +6,7 @@ export default {
.setName('settings')
.setDescription('Settings for AleeBot.')
.setContexts(0)
+ .setDefaultMemberPermissions(PermissionFlagsBits.ManageGuild)
.addSubcommand(subcommand =>
subcommand
.setName('set')
@@ -38,7 +39,10 @@ export default {
if (!interaction.member.permissions.has(PermissionFlagsBits.ManageGuild) &&
!interaction.member.permissions.has(PermissionFlagsBits.Administrator) &&
interaction.user.id !== interaction.guild.ownerId) return await interaction.reply({ content: 'You do not have the permission to manage this guild.', flags: MessageFlags.Ephemeral });
+
const guildSetting = await guildSettings.findOne({ where: { guildID: interaction.guild.id } });
+ if (!guildSetting) await guildSettings.create({ guildID: interaction.guild.id });
+
if (interaction.options.getSubcommand() === 'clear') {
await guildSettings.update({
logChannelID: null,
@@ -55,9 +59,6 @@ export default {
.setDescription('Settings for this guild.')
.setColor(abEmbedColour);
- if (!guildSetting) await guildSettings.create({ guildID: interaction.guild.id });
-
-
// Handle clearing settings
if (areAllSettingsEmpty(interaction)) {
guildEmbed.addFields(
@@ -71,6 +72,7 @@ export default {
}
// Process each setting type
+ guildEmbed.setDescription('Updated this setting.');
await updateChannelSetting(interaction, guildEmbed, 'log', 'logChannelID', 'Logging');
await updateChannelSetting(interaction, guildEmbed, 'suggestion', 'suggestionsChannelID', 'Suggestions');
await updateChannelSetting(interaction, guildEmbed, 'qotd', 'qotdChannelID', 'QOTD Channel');