mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-23 01:53:51 +02:00
Make Code Prettier
This commit is contained in:
+20
-20
@@ -76,7 +76,7 @@ class SequelizeProvider extends SettingProvider {
|
||||
let settings;
|
||||
try {
|
||||
settings = JSON.parse(row.dataValues.settings);
|
||||
} catch (err) {
|
||||
} catch(err) {
|
||||
client.emit('warn', `PostgreSQLProvider couldn't parse the settings stored for guild ${row.dataValues.guild}.`);
|
||||
continue;
|
||||
}
|
||||
@@ -84,7 +84,7 @@ class SequelizeProvider extends SettingProvider {
|
||||
const guild = row.dataValues.guild !== '0' ? row.dataValues.guild : 'global';
|
||||
|
||||
this.settings.set(guild, settings);
|
||||
if (guild !== 'global' && !client.guilds.has(row.dataValues.guild)) continue;
|
||||
if(guild !== 'global' && !client.guilds.has(row.dataValues.guild)) continue;
|
||||
this.setupGuild(guild, settings);
|
||||
}
|
||||
|
||||
@@ -95,18 +95,18 @@ class SequelizeProvider extends SettingProvider {
|
||||
.set('groupStatusChange', (guild, group, enabled) => this.set(guild, `grp-${group.id}`, enabled))
|
||||
.set('guildCreate', guild => {
|
||||
const settings = this.settings.get(guild.id);
|
||||
if (!settings) return;
|
||||
if(!settings) return;
|
||||
this.setupGuild(guild.id, settings);
|
||||
})
|
||||
.set('commandRegister', command => {
|
||||
for (const [guild, settings] of this.settings) {
|
||||
if (guild !== 'global' && !client.guilds.has(guild)) continue;
|
||||
if(guild !== 'global' && !client.guilds.has(guild)) continue;
|
||||
this.setupGuildCommand(client.guilds.get(guild), command, settings);
|
||||
}
|
||||
})
|
||||
.set('groupRegister', group => {
|
||||
for (const [guild, settings] of this.settings) {
|
||||
if (guild !== 'global' && !client.guilds.has(guild)) continue;
|
||||
if(guild !== 'global' && !client.guilds.has(guild)) continue;
|
||||
this.setupGuildGroup(client.guilds.get(guild), group, settings);
|
||||
}
|
||||
});
|
||||
@@ -127,32 +127,32 @@ class SequelizeProvider extends SettingProvider {
|
||||
async set(guild, key, val) {
|
||||
guild = this.constructor.getGuildID(guild);
|
||||
let settings = this.settings.get(guild);
|
||||
if (!settings) {
|
||||
if(!settings) {
|
||||
settings = {};
|
||||
this.settings.set(guild, settings);
|
||||
}
|
||||
|
||||
settings[key] = val;
|
||||
await this.model.upsert({ guild: guild !== 'global' ? guild : '0', settings: JSON.stringify(settings) }, { where: { guild: guild !== 'global' ? guild : '0' } }); // eslint-disable-line max-len
|
||||
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;
|
||||
await this.model.upsert({ guild: guild !== 'global' ? guild : '0', settings: JSON.stringify(settings) }, { where: { guild: guild !== 'global' ? guild : '0' } }); // eslint-disable-line max-len
|
||||
if (guild === 'global') this.updateOtherShards(key, undefined);
|
||||
if(guild === 'global') this.updateOtherShards(key, undefined);
|
||||
return val;
|
||||
}
|
||||
|
||||
async clear(guild) {
|
||||
guild = this.constructor.getGuildID(guild);
|
||||
if (!this.settings.has(guild)) return;
|
||||
if(!this.settings.has(guild)) return;
|
||||
this.settings.delete(guild);
|
||||
await this.model.destroy({ where: { guild: guild !== 'global' ? guild : '0' } });
|
||||
}
|
||||
@@ -164,12 +164,12 @@ 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;
|
||||
if(typeof settings.prefix !== 'undefined') {
|
||||
if(guild) guild._commandPrefix = settings.prefix;
|
||||
else this.client._commandPrefix = settings.prefix;
|
||||
}
|
||||
|
||||
@@ -186,9 +186,9 @@ class SequelizeProvider extends SettingProvider {
|
||||
* @private
|
||||
*/
|
||||
setupGuildCommand(guild, command, settings) {
|
||||
if (typeof settings[`cmd-${command.name}`] === 'undefined') return;
|
||||
if (guild) {
|
||||
if (!guild._commandsEnabled) guild._commandsEnabled = {};
|
||||
if(typeof settings[`cmd-${command.name}`] === 'undefined') return;
|
||||
if(guild) {
|
||||
if(!guild._commandsEnabled) guild._commandsEnabled = {};
|
||||
guild._commandsEnabled[command.name] = settings[`cmd-${command.name}`];
|
||||
} else {
|
||||
command._globalEnabled = settings[`cmd-${command.name}`];
|
||||
@@ -203,9 +203,9 @@ class SequelizeProvider extends SettingProvider {
|
||||
* @private
|
||||
*/
|
||||
setupGuildGroup(guild, group, settings) {
|
||||
if (typeof settings[`grp-${group.id}`] === 'undefined') return;
|
||||
if (guild) {
|
||||
if (!guild._groupsEnabled) guild._groupsEnabled = {};
|
||||
if(typeof settings[`grp-${group.id}`] === 'undefined') return;
|
||||
if(guild) {
|
||||
if(!guild._groupsEnabled) guild._groupsEnabled = {};
|
||||
guild._groupsEnabled[group.id] = settings[`grp-${group.id}`];
|
||||
} else {
|
||||
group._globalEnabled = settings[`grp-${group.id}`];
|
||||
@@ -219,7 +219,7 @@ class SequelizeProvider extends SettingProvider {
|
||||
* @private
|
||||
*/
|
||||
updateOtherShards(key, val) {
|
||||
if (!this.client.shard) return;
|
||||
if(!this.client.shard) return;
|
||||
key = JSON.stringify(key);
|
||||
val = typeof val !== 'undefined' ? JSON.stringify(val) : 'undefined';
|
||||
this.client.shard.broadcastEval(`
|
||||
|
||||
Reference in New Issue
Block a user