perm checks

This commit is contained in:
Erik 2022-05-10 21:40:57 +03:00
parent cbcc3131d5
commit 2ae5a20287
Signed by: Navy.gif
GPG Key ID: 811EC0CD80E7E5FB
2 changed files with 14 additions and 11 deletions

View File

@ -159,7 +159,7 @@ class GuildLogger extends Observer {
const logChannel = await wrapper.resolveChannel(messageLog.channel);
if (!logChannel) return undefined;
const missing = logChannel.permissionsFor(wrapper.me).missing(['VIEW_CHANNEL', 'EMBED_LINKS', 'SEND_MESSAGES']);
const missing = logChannel.permissionsFor(wrapper.me).missing(['VIEW_CHANNEL', 'EMBED_LINKS', 'SEND_MESSAGES', 'MANAGE_WEBHOOKS']);
if (missing.length)
return this.client.emit('logError', { guild: wrapper, logger: 'messageLogger', reason: 'MSGLOG_NO_PERMS', params: { missing: missing.join(', ') } });
@ -334,7 +334,7 @@ class GuildLogger extends Observer {
const { ignore, bypass } = chatlogs;
if (ignore.includes(channel.id)) return;
const missing = logChannel.permissionsFor(guild.me).missing(['VIEW_CHANNEL', 'EMBED_LINKS', 'SEND_MESSAGES']);
const missing = logChannel.permissionsFor(guild.me).missing(['VIEW_CHANNEL', 'EMBED_LINKS', 'SEND_MESSAGES', 'MANAGE_WEBHOOKS']);
if (missing.length)
return this.client.emit('logError', { guild: wrapper, logger: 'messageLogger', reason: 'MSGLOG_NO_PERMS', params: { missing: missing.join(', ') } });
@ -517,7 +517,7 @@ class GuildLogger extends Observer {
const logChannel = await wrapper.resolveChannel(_channel);
if (!logChannel) return undefined;
const missing = logChannel.permissionsFor(guild.me).missing(['VIEW_CHANNEL', 'EMBED_LINKS', 'SEND_MESSAGES']);
const missing = logChannel.permissionsFor(guild.me).missing(['VIEW_CHANNEL', 'EMBED_LINKS', 'SEND_MESSAGES', 'MANAGE_WEBHOOKS']);
if (missing.length)
return this.client.emit('logError', { guild: wrapper, logger: 'messageLogger', reason: 'MSGLOG_NO_PERMS', params: { missing: missing.join(', ') } });
@ -580,7 +580,8 @@ class GuildLogger extends Observer {
embed.fields.push({
name: wrapper.format('MSGLOG_EDIT_OLD'),
// eslint-disable-next-line no-nested-ternary
value: oldCon.length > 1024 ? oldCon.substring(0, 1021) + '...' : oldCon.length ? oldCon : '\u200b'
value: oldCon.length > 1024 ?
oldCon.substring(0, 1021) + '...' : oldCon.length ? oldCon : '\u200b'
});
if (oldCon.length > 1024) embed.fields.push({
name: '\u200b',
@ -589,7 +590,8 @@ class GuildLogger extends Observer {
//Edited content
embed.fields.push({
name: wrapper.format('MSGLOG_EDIT_NEW'),
value: newCon.length > 1024 ? newCon.substring(0, 1021) + '...' : newCon
// eslint-disable-next-line no-nested-ternary
value: newCon.length > 1024 ? newCon.substring(0, 1021) + '...' : newCon.length ? newCon : '\u200b'
});
if (newCon.length > 1024) embed.fields.push({
name: '\u200b',

View File

@ -198,20 +198,21 @@ class Setting extends Component {
}
// Helper function for prompting for user response by editing the interaction response
async _prompt(interaction, { message= '', params = {}, embed, index, time = 120 }) {
async _prompt(invoker, { message= '', params = {}, embed, index, time = 120 }) {
if (!message.length && !index && !embed) throw new Error('Must declare either message, index or embeds');
const response = await interaction.promptMessage(
index ? interaction.format(index, params) : message,
const response = await invoker.promptMessage(
index ? invoker.format(index, params) : message,
{ time, editReply: true, embed }
);
if (!response) return { error: true, message: interaction.format('ERR_TIMEOUT') };
if (!response) return { error: true, message: invoker.format('ERR_TIMEOUT') };
const content = response.content.toLowerCase();
await response.delete();
if(invoker.channel.permissionsFor(invoker.guild.me).has('MANAGE_MESSAGES'))
await response.delete();
if (['cancel', 'abort', 'exit'].includes(content)) return {
error: true,
message: interaction.format('ERR_CANCEL')
message: invoker.format('ERR_CANCEL')
};
else if (!content.length) return { error: true, index: 'SETTING_NOCONTENT' };