Skip to content

Commit dcd5698

Browse files
committed
Redid Overrides + command
1 parent da5e128 commit dcd5698

File tree

6 files changed

+593
-52
lines changed

6 files changed

+593
-52
lines changed

commands/Starboard/starboard.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,11 @@ class Starboard extends Command {
6060

6161
const starKey = Object.keys(starboards).find((key) => key.toLowerCase() === name.toLowerCase());
6262
if (starboards[starKey]) {
63-
return msg.channel.send(`A starboard named "${name}" already exists!`);
63+
return msg.channel.send(`A starboard named \`${name}\` already exists.`);
6464
}
6565

6666
if (!channel || !channel.permissionsFor(msg.guild.members.me).has(['SendMessages', 'ViewChannel'])) {
67-
return msg.channel.send('Please specify a valid channel where I have permission to send messages!');
67+
return msg.channel.send('Please specify a valid channel where I have permission to send messages.');
6868
}
6969

7070
await db.set(`servers.${msg.guild.id}.starboards.${name}`, {
@@ -90,23 +90,23 @@ class Starboard extends Command {
9090
messages: {},
9191
});
9292

93-
return msg.channel.send(`Created starboard "${name}" in ${channel}.`);
93+
return msg.channel.send(`Created starboard \`${name}\` in ${channel}.`);
9494
}
9595

9696
case 'delete': {
9797
if (!args[1]) {
98-
return msg.channel.send('Please specify a starboard name to delete!');
98+
return msg.channel.send('Please specify a starboard name to delete.');
9999
}
100100

101101
const name = args[1];
102102

103103
const starKey = Object.keys(starboards).find((key) => key.toLowerCase() === name.toLowerCase());
104104
if (!starboards[starKey]) {
105-
return msg.channel.send(`No starboard named "${name}" exists!`);
105+
return msg.channel.send(`No starboard named \`${name}\` exists.`);
106106
}
107107

108108
await db.delete(`servers.${msg.guild.id}.starboards.${name}`);
109-
return msg.channel.send(`Deleted starboard "${name}"!`);
109+
return msg.channel.send(`Deleted starboard \`${name}\`.`);
110110
}
111111

112112
default:

events/Message/messageReactionAdd.mjs

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,24 +27,26 @@ export async function run(client, messageReaction, user) {
2727
}
2828

2929
const starboards = (await db.get(`servers.${msg.guild.id}.starboards`)) || {};
30+
const overrides = (await db.get(`servers.${msg.guild.id}.overrides`)) || {};
3031

31-
for (const [name, oldConfig] of Object.entries(starboards)) {
32-
const getStarboardConfig = (config, channelId) => {
33-
if (!config) return null;
32+
const getStarboardConfig = (starboardName, channelId) => {
33+
const baseConfig = starboards[starboardName];
34+
if (!baseConfig) return null;
3435

35-
// Check if any override applies to this channel
36-
if (config.overrides) {
37-
for (const [overrideName, overrideConfig] of Object.entries(config.overrides)) {
38-
if (overrideConfig.channels.includes(channelId)) {
39-
return { ...config, ...overrideConfig, overrideName };
40-
}
41-
}
36+
// Find the first override that applies to this channel
37+
for (const [overrideName, overrideConfig] of Object.entries(overrides)) {
38+
if (overrideConfig.starboard === starboardName && overrideConfig.channels.includes(channelId)) {
39+
return { ...baseConfig, ...overrideConfig, overrideName };
4240
}
41+
}
4342

44-
return config; // Return default if no override is found
45-
};
43+
return baseConfig; // Default config if no override applies
44+
};
45+
46+
for (const name of Object.keys(starboards)) {
47+
const config = getStarboardConfig(name, msg.channel.id);
48+
// Now you can use `config`, which will either be the default starboard config or an overridden one
4649

47-
const config = getStarboardConfig(oldConfig, msg.channel.id);
4850
if (!config.enabled) continue;
4951
if (msg.author.bot && !config['allow-bots']) continue;
5052

events/Message/messageReactionRemove.mjs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,24 +27,25 @@ export async function run(client, messageReaction, user) {
2727
}
2828

2929
const starboards = (await db.get(`servers.${msg.guild.id}.starboards`)) || {};
30+
const overrides = (await db.get(`servers.${msg.guild.id}.overrides`)) || {};
3031

31-
for (const [name, oldConfig] of Object.entries(starboards)) {
32-
const getStarboardConfig = (config, channelId) => {
33-
if (!config) return null;
32+
const getStarboardConfig = (starboardName, channelId) => {
33+
const baseConfig = starboards[starboardName];
34+
if (!baseConfig) return null;
3435

35-
// Check if any override applies to this channel
36-
if (config.overrides) {
37-
for (const [overrideName, overrideConfig] of Object.entries(config.overrides)) {
38-
if (overrideConfig.channels.includes(channelId)) {
39-
return { ...config, ...overrideConfig, overrideName };
40-
}
41-
}
36+
// Find the first override that applies to this channel
37+
for (const [overrideName, overrideConfig] of Object.entries(overrides)) {
38+
if (overrideConfig.starboard === starboardName && overrideConfig.channels.includes(channelId)) {
39+
return { ...baseConfig, ...overrideConfig, overrideName };
4240
}
41+
}
4342

44-
return config; // Return default if no override is found
45-
};
43+
return baseConfig; // Default config if no override applies
44+
};
4645

47-
const config = getStarboardConfig(oldConfig, msg.channel.id);
46+
for (const name of Object.keys(starboards)) {
47+
const config = getStarboardConfig(name, msg.channel.id);
48+
// Now you can use `config`, which will either be the default starboard config or an overridden one
4849
if (!config.enabled) continue;
4950
if (msg.author.bot && !config['allow-bots']) continue;
5051

events/Message/messageUpdate.mjs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -205,24 +205,25 @@ export async function run(client, oldMessage, newMessage) {
205205
if (newMessage.partial) await newMessage.fetch(); // Ensure we have full message data
206206

207207
const starboards = (await db.get(`servers.${oldMessage.guild.id}.starboards`)) || {};
208+
const overrides = (await db.get(`servers.${oldMessage.guild.id}.overrides`)) || {};
208209

209-
for (const [name, oldConfig] of Object.entries(starboards)) {
210-
const getStarboardConfig = (config, channelId) => {
211-
if (!config) return null;
210+
const getStarboardConfig = (starboardName, channelId) => {
211+
const baseConfig = starboards[starboardName];
212+
if (!baseConfig) return null;
212213

213-
// Check if any override applies to this channel
214-
if (config.overrides) {
215-
for (const [overrideName, overrideConfig] of Object.entries(config.overrides)) {
216-
if (overrideConfig.channels.includes(channelId)) {
217-
return { ...config, ...overrideConfig, overrideName };
218-
}
219-
}
214+
// Find the first override that applies to this channel
215+
for (const [overrideName, overrideConfig] of Object.entries(overrides)) {
216+
if (overrideConfig.starboard === starboardName && overrideConfig.channels.includes(channelId)) {
217+
return { ...baseConfig, ...overrideConfig, overrideName };
220218
}
219+
}
221220

222-
return config; // Return default if no override is found
223-
};
221+
return baseConfig; // Default config if no override applies
222+
};
224223

225-
const config = getStarboardConfig(oldConfig, newMessage.channel.id);
224+
for (const name of Object.keys(starboards)) {
225+
const config = getStarboardConfig(name, newMessage.channel.id);
226+
// Now you can use `config`, which will either be the default starboard config or an overridden one
226227

227228
if (!config.enabled) continue;
228229
if (!config['link-edits']) continue;

0 commit comments

Comments
 (0)