fix dumb issue

This commit is contained in:
Erik 2020-08-17 23:24:43 +03:00
parent d094ffa765
commit d3c16ec89e
2 changed files with 47 additions and 29 deletions

View File

@ -178,7 +178,7 @@ class Resolver {
if (_resolved) {
if(!resolved.includes(_resolved[0])) resolved.push(_resolved[0]);
elem = _resolved[0].id;
}
} else continue;
}
if(!caseSensitive) elem = elem.toLowerCase();
@ -201,7 +201,7 @@ class Resolver {
if (_resolved) {
if (!resolved.includes(_resolved[0])) resolved.push(_resolved[0]);
elem = _resolved[0].id;
}
} else continue;
}
if (!caseSensitive) elem = elem.toLowerCase();
@ -223,7 +223,7 @@ class Resolver {
if (_resolved) {
if (!resolved.includes(_resolved[0])) resolved.push(_resolved[0]);
elem = _resolved[0].id;
}
} else continue;
}
if (!caseSensitive) elem = elem.toLowerCase();
@ -527,7 +527,15 @@ class Resolver {
return date;
}
/**
* Iterate through several arguments attempting to resolve them with the passed resolvers
*
* @param {Array<string>} [args=[]]
* @param {Array<Function>} [resolvers=[]]
* @param {boolean} strict
* @param {Guild} guild
* @returns
*/
async infinite(args = [], resolvers = [], strict, guild) {
let parsed = [], //eslint-disable-line prefer-const
parameters = [];

View File

@ -62,6 +62,7 @@ class MessageLogsSetting extends Setting {
if (response.method === 'add') {
const roles = response.resolved;
if (!roles.length) return { error: true, msg: message.format('ERR_ROLERESOLVE') }
setting.ignoredRoles = [...setting.ignoredRoles, ...roles.filter((r) => !setting.ignoredRoles.includes(r.id)).map((r) => r.id)];
action = 'GENERAL_ADDED';
@ -71,6 +72,7 @@ class MessageLogsSetting extends Setting {
} else if (response.method === 'remove') {
const roles = response.resolved;
if (!roles.length) return { error: true, msg: message.format('ERR_ROLERESOLVE') }
const _roles = roles.map((r) => r.id);
setting.ignoredRoles = setting.ignoredRoles.filter((r) => !_roles.includes(r));
@ -100,13 +102,14 @@ class MessageLogsSetting extends Setting {
msg: message.format('MISSING_ARGS'),
error: true
};
const response = await this.resolveMethod(args);
const response = await this.resolveMethod(args, null, setting.ignoredChannels, guild.resolveChannels.bind(guild));
if (response) {
if (response.method === 'add') {
const channels = await guild.resolveChannels(response.rest);
const channels = response.resolved; //await guild.resolveChannels(response.rest);
if (!channels.length) return { error: true, msg: message.format('ERR_CHRESOLVE') }
setting.ignoredChannels = [...setting.ignoredChannels, ...channels.filter((c) => !setting.ignoredChannels.includes(c.id)).map((c) => c.id)];
action = 'GENERAL_ADDED';
@ -115,7 +118,8 @@ class MessageLogsSetting extends Setting {
} else if (response.method === 'remove') {
const channels = await guild.resolveChannels(response.rest);
const channels = response.resolved; //await guild.resolveChannels(response.rest);
if (!channels.length) return { error: true, msg: message.format('ERR_CHRESOLVE') }
const _channels = channels.map((c) => c.id);
setting.ignoredChannels = setting.ignoredChannels.filter((c) => !_channels.includes(c));
@ -129,8 +133,6 @@ class MessageLogsSetting extends Setting {
};
}
changes = response.changed;
} else {
const channels = await guild.resolveChannels(setting.ignoredChannels);
return {
@ -175,13 +177,15 @@ class MessageLogsSetting extends Setting {
if (setting.webhook) { //Clean up - remove webhook since logs were disabled
const channel = await guild.resolveChannel(setting.channel);
if (channel) { //Channel might have been deleted
const hooks = channel.fetchWebhooks();
const hook = hooks.filter((hook) => hook.id === setting.webhook).first();
guild.webhooks.delete(setting.webhook);
setting.webhook = null;
const hooks = await channel.fetchWebhooks();
const hook = hooks.filter((hook) => hook.id === setting.webhook.id).first();
if (hook && !channel.permissionsFor(guild.me).has('MANAGE_WEBHOOKS')) index = 'S_MESSAGELOG_TOGGLE_PERM'; //missing perms
else if (hook) await hook.delete('Removing message logging hook, as message logs were disabled.').catch(this.client.logger.error);
if (hook && !channel.permissionsFor(guild.me).has('MANAGE_WEBHOOKS')) return { error: true, msg: message.format('S_MESSAGELOG_TOGGLE_PERM') } //index = 'S_MESSAGELOG_TOGGLE_PERM'; //missing perms
else if (hook) {
//await hook.delete('Removing message logging hook, as message logs were disabled.').catch(this.client.logger.error);
//guild.webhooks.delete(setting.webhook);
await guild.updateWebhook(this.index);
}
}
}
@ -200,28 +204,28 @@ class MessageLogsSetting extends Setting {
};
const perms = channel.permissionsFor(guild.me);
const missingPerms = [];
if(!perms.has('SEND_MESSAGES')) missingPerms.push('SEND_MESSAGES');
if(!perms.has('VIEW_CHANNEL')) missingPerms.push('VIEW_CHANNEL');
const missingPerms = perms.missing(['SEND_MESSAGES', 'VIEW_CHANNEL', 'MANAGE_WEBHOOKS']);
if(missingPerms.length) return {
error: true,
msg: message.format('ERR_CHANNEL_PERMS', { channel: channel.name, perms: missingPerms.join(', ') })
};
// //Handle old webhook if one exists
// const oldChannel = guild.resolveChannel(setting.channel);
// if (oldChannel && chatlogs.webhook && oldChannel.id !== channel.id) {
// const hooks = await oldChannel.fetchWebhooks();
// const hook = hooks.filter(hook => hook.id === setting.webhook).first();
//Handle old webhook if one exists
const oldChannel = await guild.resolveChannel(setting.channel);
if (oldChannel && oldChannel.id !== channel.id) {
const hooks = await oldChannel.fetchWebhooks();
const hook = hooks.filter(hook => hook.id === setting.webhook.id).first();
// guild.webhooks.delete(hook.id);
// if (hook) hook.delete('Removing old webhook').catch(this.client.logger.error);
// }
if (hook) {
guild.updateWebhook(this.index);
//hook.delete('Removing old webhook').catch(this.client.logger.error);
}
}
// if(oldChannel && oldChannel.id !== channel.id) {
// }
//Create new webhook
const hook = await channel.createWebhook('Galactic Bot message logs', { avatar: './util/GBotTest.png', reason: 'Message logs webhook.' });
await guild.updateWebhook(this.index, hook);
index = 'S_MESSAGELOG_CHANNEL';
changes = channel.name;
@ -267,6 +271,12 @@ class MessageLogsSetting extends Setting {
];
}
async _handleReset(message) {
const result = await super._handleReset(message);
await message.guild.updateWebhook(this.index);
return result;
}
}
module.exports = MessageLogsSetting;