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) {
if(!resolved.includes(_resolved[0])) resolved.push(_resolved[0]); if(!resolved.includes(_resolved[0])) resolved.push(_resolved[0]);
elem = _resolved[0].id; elem = _resolved[0].id;
} } else continue;
} }
if(!caseSensitive) elem = elem.toLowerCase(); if(!caseSensitive) elem = elem.toLowerCase();
@ -201,7 +201,7 @@ class Resolver {
if (_resolved) { if (_resolved) {
if (!resolved.includes(_resolved[0])) resolved.push(_resolved[0]); if (!resolved.includes(_resolved[0])) resolved.push(_resolved[0]);
elem = _resolved[0].id; elem = _resolved[0].id;
} } else continue;
} }
if (!caseSensitive) elem = elem.toLowerCase(); if (!caseSensitive) elem = elem.toLowerCase();
@ -223,7 +223,7 @@ class Resolver {
if (_resolved) { if (_resolved) {
if (!resolved.includes(_resolved[0])) resolved.push(_resolved[0]); if (!resolved.includes(_resolved[0])) resolved.push(_resolved[0]);
elem = _resolved[0].id; elem = _resolved[0].id;
} } else continue;
} }
if (!caseSensitive) elem = elem.toLowerCase(); if (!caseSensitive) elem = elem.toLowerCase();
@ -527,7 +527,15 @@ class Resolver {
return date; 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) { async infinite(args = [], resolvers = [], strict, guild) {
let parsed = [], //eslint-disable-line prefer-const let parsed = [], //eslint-disable-line prefer-const
parameters = []; parameters = [];

View File

@ -62,6 +62,7 @@ class MessageLogsSetting extends Setting {
if (response.method === 'add') { if (response.method === 'add') {
const roles = response.resolved; 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)]; setting.ignoredRoles = [...setting.ignoredRoles, ...roles.filter((r) => !setting.ignoredRoles.includes(r.id)).map((r) => r.id)];
action = 'GENERAL_ADDED'; action = 'GENERAL_ADDED';
@ -71,6 +72,7 @@ class MessageLogsSetting extends Setting {
} else if (response.method === 'remove') { } else if (response.method === 'remove') {
const roles = response.resolved; const roles = response.resolved;
if (!roles.length) return { error: true, msg: message.format('ERR_ROLERESOLVE') }
const _roles = roles.map((r) => r.id); const _roles = roles.map((r) => r.id);
setting.ignoredRoles = setting.ignoredRoles.filter((r) => !_roles.includes(r)); setting.ignoredRoles = setting.ignoredRoles.filter((r) => !_roles.includes(r));
@ -100,13 +102,14 @@ class MessageLogsSetting extends Setting {
msg: message.format('MISSING_ARGS'), msg: message.format('MISSING_ARGS'),
error: true 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) {
if (response.method === 'add') { 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)]; setting.ignoredChannels = [...setting.ignoredChannels, ...channels.filter((c) => !setting.ignoredChannels.includes(c.id)).map((c) => c.id)];
action = 'GENERAL_ADDED'; action = 'GENERAL_ADDED';
@ -115,7 +118,8 @@ class MessageLogsSetting extends Setting {
} else if (response.method === 'remove') { } 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); const _channels = channels.map((c) => c.id);
setting.ignoredChannels = setting.ignoredChannels.filter((c) => !_channels.includes(c)); setting.ignoredChannels = setting.ignoredChannels.filter((c) => !_channels.includes(c));
@ -129,8 +133,6 @@ class MessageLogsSetting extends Setting {
}; };
} }
changes = response.changed;
} else { } else {
const channels = await guild.resolveChannels(setting.ignoredChannels); const channels = await guild.resolveChannels(setting.ignoredChannels);
return { return {
@ -175,13 +177,15 @@ class MessageLogsSetting extends Setting {
if (setting.webhook) { //Clean up - remove webhook since logs were disabled if (setting.webhook) { //Clean up - remove webhook since logs were disabled
const channel = await guild.resolveChannel(setting.channel); const channel = await guild.resolveChannel(setting.channel);
if (channel) { //Channel might have been deleted if (channel) { //Channel might have been deleted
const hooks = channel.fetchWebhooks(); const hooks = await channel.fetchWebhooks();
const hook = hooks.filter((hook) => hook.id === setting.webhook).first(); const hook = hooks.filter((hook) => hook.id === setting.webhook.id).first();
guild.webhooks.delete(setting.webhook);
setting.webhook = null;
if (hook && !channel.permissionsFor(guild.me).has('MANAGE_WEBHOOKS')) index = 'S_MESSAGELOG_TOGGLE_PERM'; //missing perms 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); 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 perms = channel.permissionsFor(guild.me);
const missingPerms = []; const missingPerms = perms.missing(['SEND_MESSAGES', 'VIEW_CHANNEL', 'MANAGE_WEBHOOKS']);
if(!perms.has('SEND_MESSAGES')) missingPerms.push('SEND_MESSAGES');
if(!perms.has('VIEW_CHANNEL')) missingPerms.push('VIEW_CHANNEL');
if(missingPerms.length) return { if(missingPerms.length) return {
error: true, error: true,
msg: message.format('ERR_CHANNEL_PERMS', { channel: channel.name, perms: missingPerms.join(', ') }) msg: message.format('ERR_CHANNEL_PERMS', { channel: channel.name, perms: missingPerms.join(', ') })
}; };
// //Handle old webhook if one exists //Handle old webhook if one exists
// const oldChannel = guild.resolveChannel(setting.channel); const oldChannel = await guild.resolveChannel(setting.channel);
// if (oldChannel && chatlogs.webhook && oldChannel.id !== channel.id) { if (oldChannel && oldChannel.id !== channel.id) {
// const hooks = await oldChannel.fetchWebhooks(); const hooks = await oldChannel.fetchWebhooks();
// const hook = hooks.filter(hook => hook.id === setting.webhook).first(); const hook = hooks.filter(hook => hook.id === setting.webhook.id).first();
// guild.webhooks.delete(hook.id); if (hook) {
// if (hook) hook.delete('Removing old webhook').catch(this.client.logger.error); 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'; index = 'S_MESSAGELOG_CHANNEL';
changes = channel.name; 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; module.exports = MessageLogsSetting;