mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-21 05:54:33 +02:00
22.0.0
This commit is contained in:
+38
-15
@@ -93,29 +93,33 @@ class SequelizeProvider extends SettingProvider {
|
||||
.set('commandPrefixChange', (guild, prefix) => this.set(guild, 'prefix', prefix))
|
||||
.set('commandStatusChange', (guild, command, enabled) => this.set(guild, `cmd-${command.name}`, enabled))
|
||||
.set('groupStatusChange', (guild, group, enabled) => this.set(guild, `grp-${group.id}`, enabled))
|
||||
.set('guildCreate', guild => {
|
||||
.set('guildCreate', (guild) => {
|
||||
const settings = this.settings.get(guild.id);
|
||||
if (!settings) return;
|
||||
this.setupGuild(guild.id, settings);
|
||||
})
|
||||
.set('commandRegister', command => {
|
||||
.set('commandRegister', (command) => {
|
||||
for (const [guild, settings] of this.settings) {
|
||||
if (guild !== 'global' && !client.guilds.has(guild)) continue;
|
||||
this.setupGuildCommand(client.guilds.get(guild), command, settings);
|
||||
}
|
||||
})
|
||||
.set('groupRegister', group => {
|
||||
.set('groupRegister', (group) => {
|
||||
for (const [guild, settings] of this.settings) {
|
||||
if (guild !== 'global' && !client.guilds.has(guild)) continue;
|
||||
this.setupGuildGroup(client.guilds.get(guild), group, settings);
|
||||
}
|
||||
});
|
||||
for (const [event, listener] of this.listeners) client.on(event, listener);
|
||||
for (const [event, listener] of this.listeners) {
|
||||
client.on(event, listener);
|
||||
}
|
||||
}
|
||||
|
||||
destroy() {
|
||||
// Remove all listeners from the client
|
||||
for (const [event, listener] of this.listeners) this.client.removeListener(event, listener);
|
||||
for (const [event, listener] of this.listeners) {
|
||||
this.client.removeListener(event, listener);
|
||||
}
|
||||
this.listeners.clear();
|
||||
}
|
||||
|
||||
@@ -137,14 +141,18 @@ class SequelizeProvider extends SettingProvider {
|
||||
{ guild: guild !== 'global' ? guild : '0', settings: JSON.stringify(settings) },
|
||||
{ where: { guild: guild !== 'global' ? guild : '0' } }
|
||||
);
|
||||
if (guild === 'global') this.updateOtherShards(key, val);
|
||||
if (guild === 'global') {
|
||||
this.updateOtherShards(key, val);
|
||||
}
|
||||
return val;
|
||||
}
|
||||
|
||||
async remove(guild, key) {
|
||||
guild = this.constructor.getGuildID(guild);
|
||||
const settings = this.settings.get(guild);
|
||||
if (!settings || typeof settings[key] === 'undefined') return undefined;
|
||||
if (!settings || typeof settings[key] === 'undefined') {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const val = settings[key];
|
||||
settings[key] = undefined;
|
||||
@@ -152,7 +160,9 @@ class SequelizeProvider extends SettingProvider {
|
||||
{ guild: guild !== 'global' ? guild : '0', settings: JSON.stringify(settings) },
|
||||
{ where: { guild: guild !== 'global' ? guild : '0' } }
|
||||
);
|
||||
if (guild === 'global') this.updateOtherShards(key, undefined);
|
||||
if (guild === 'global') {
|
||||
this.updateOtherShards(key, undefined);
|
||||
}
|
||||
return val;
|
||||
}
|
||||
|
||||
@@ -170,18 +180,27 @@ class SequelizeProvider extends SettingProvider {
|
||||
* @private
|
||||
*/
|
||||
setupGuild(guild, settings) {
|
||||
if (typeof guild !== 'string') throw new TypeError('The guild must be a guild ID or "global".');
|
||||
if (typeof guild !== 'string') {
|
||||
throw new TypeError('The guild must be a guild ID or "global".');
|
||||
}
|
||||
guild = this.client.guilds.get(guild) || null;
|
||||
|
||||
// Load the command prefix
|
||||
if (typeof settings.prefix !== 'undefined') {
|
||||
if (guild) guild._commandPrefix = settings.prefix;
|
||||
else this.client._commandPrefix = settings.prefix;
|
||||
if (guild) {
|
||||
guild._commandPrefix = settings.prefix;
|
||||
} else {
|
||||
this.client._commandPrefix = settings.prefix;
|
||||
}
|
||||
}
|
||||
|
||||
// Load all command/group statuses
|
||||
for (const command of this.client.registry.commands.values()) this.setupGuildCommand(guild, command, settings);
|
||||
for (const group of this.client.registry.groups.values()) this.setupGuildGroup(guild, group, settings);
|
||||
for (const command of this.client.registry.commands.values()) {
|
||||
this.setupGuildCommand(guild, command, settings);
|
||||
}
|
||||
for (const group of this.client.registry.groups.values()) {
|
||||
this.setupGuildGroup(guild, group, settings);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -194,7 +213,9 @@ class SequelizeProvider extends SettingProvider {
|
||||
setupGuildCommand(guild, command, settings) {
|
||||
if (typeof settings[`cmd-${command.name}`] === 'undefined') return;
|
||||
if (guild) {
|
||||
if (!guild._commandsEnabled) guild._commandsEnabled = {};
|
||||
if (!guild._commandsEnabled) {
|
||||
guild._commandsEnabled = {};
|
||||
}
|
||||
guild._commandsEnabled[command.name] = settings[`cmd-${command.name}`];
|
||||
} else {
|
||||
command._globalEnabled = settings[`cmd-${command.name}`];
|
||||
@@ -211,7 +232,9 @@ class SequelizeProvider extends SettingProvider {
|
||||
setupGuildGroup(guild, group, settings) {
|
||||
if (typeof settings[`grp-${group.id}`] === 'undefined') return;
|
||||
if (guild) {
|
||||
if (!guild._groupsEnabled) guild._groupsEnabled = {};
|
||||
if (!guild._groupsEnabled) {
|
||||
guild._groupsEnabled = {};
|
||||
}
|
||||
guild._groupsEnabled[group.id] = settings[`grp-${group.id}`];
|
||||
} else {
|
||||
group._globalEnabled = settings[`grp-${group.id}`];
|
||||
|
||||
Reference in New Issue
Block a user