diff --git a/server/bot/commands/admin/ban.ts b/server/bot/commands/admin/ban.ts index 9ea5450..28e2872 100644 --- a/server/bot/commands/admin/ban.ts +++ b/server/bot/commands/admin/ban.ts @@ -44,24 +44,34 @@ export const handleBan: Command = { // If the user cannot ban the person.. if ( message.member.guild.members.find(i => i.user === user) && - checkRolePosition(message.member.guild.members.find(i => i.user === user)) >= + checkRolePosition(message.member.guild.members.get(user.id)) >= checkRolePosition(message.member) - ) { - return `You cannot ban this person, you ${getInsult()}.` - } + ) return `You cannot ban this person, you ${getInsult()}.` // Now we ban the person. const f = parseSilentDelete(args) - try { - await client.banGuildMember(message.member.guild.id, user.id, 0, args.join(' ')) - } catch (e) { return 'That person could not be banned.' } + // If we can't ban the person.. + if ( + message.member.guild.members.find(i => i.user === user) && + (checkRolePosition(message.member.guild.members.get(user.id)) >= + checkRolePosition(message.member.guild.members.get(client.user.id)) || + message.member.guild.members.get(client.user.id).permission.has('banMembers')) + ) return `I cannot ban this person, you ${getInsult()}.` + let dm try { if (!f.silent) { - await client.createMessage((await client.getDMChannel(user.id)).id, f.args.length !== 0 - ? `You have been banned from ${message.member.guild.name} for ${f.args.join(' ')}.` - : `You have been banned from ${message.member.guild.name}.` + dm = await client.createMessage((await client.getDMChannel(user.id)).id, + f.args.length !== 0 + ? `You have been banned from ${message.member.guild.name} for ${f.args.join(' ')}.` + : `You have been banned from ${message.member.guild.name}.` ) } } catch (e) {} + try { + await client.banGuildMember(message.member.guild.id, user.id, 0, args.join(' ')) + } catch (e) { + if (dm) dm.delete() + return 'That person could not be banned.' + } // WeChill if (message.member.guild.id === '402423671551164416') { client.createMessage('402437089557217290', f.args.length !== 0 diff --git a/server/bot/commands/admin/index.ts b/server/bot/commands/admin/index.ts index b8a6a38..95a0282 100644 --- a/server/bot/commands/admin/index.ts +++ b/server/bot/commands/admin/index.ts @@ -52,7 +52,8 @@ export const handlePurge: Command = { } catch (e) { return 'Could not retrieve messages.' } // Delete the messages. try { - client.deleteMessages(message.channel.id, messages.map(i => i.id), args.join(' ') || 'Purge') + const reason = args.join(' ') || 'Purge' + await client.deleteMessages(message.channel.id, messages.map(i => i.id), reason) } catch (e) { return 'Could not delete messages. Are the messages older than 2 weeks?' } } } @@ -73,21 +74,36 @@ export const handleKick: Command = { if (!user) return `Specify a valid member of this guild, ${getInsult()}.` // If the user cannot kick the person.. if ( - checkRolePosition(message.member.guild.members.find(i => i.user === user)) >= + checkRolePosition(message.member.guild.members.get(user.id)) >= checkRolePosition(message.member) ) { return `You cannot kick this person, you ${getInsult()}.` } // Now we kick the person. const f = parseSilentDelete(args) + // If we can't ban the person.. + if ( + message.member.guild.members.find(i => i.user === user) && + (checkRolePosition(message.member.guild.members.get(user.id)) >= + checkRolePosition(message.member.guild.members.get(client.user.id)) || + message.member.guild.members.get(client.user.id).permission.has('banMembers')) + ) return `I cannot kick this person, you ${getInsult()}.` + // Notify the user. + let dm + if (!f.silent) { + try { + dm = await client.createMessage((await client.getDMChannel(user.id)).id, + f.args.length !== 0 + ? `You have been kicked from ${message.member.guild.name} for ${f.args.join(' ')}.` + : `You have been kicked from ${message.member.guild.name}.` + ) + } catch (e) {} + } try { await client.kickGuildMember(message.member.guild.id, user.id, args.join(' ')) - } catch (e) { return 'I am unable to kick that user.' } - if (!f.silent) { - client.createMessage((await client.getDMChannel(user.id)).id, f.args.length !== 0 - ? `You have been kicked from ${message.member.guild.name} for ${f.args.join(' ')}.` - : `You have been kicked from ${message.member.guild.name}.` - ) + } catch (e) { + if (dm) dm.delete() + return 'I am unable to kick that user.' } // WeChill if (message.member.guild.id === '402423671551164416') { diff --git a/server/bot/commands/api.ts b/server/bot/commands/api.ts index 8f2b781..7ee3dc8 100644 --- a/server/bot/commands/api.ts +++ b/server/bot/commands/api.ts @@ -193,7 +193,7 @@ export const handleDog: Command = { const { message } = await (await fetch( `http://dog.ceo/api/breed/${args[0].toLowerCase()}/${args[1].toLowerCase()}/images/random` )).json() - if (!message) return 'This breed/sub-breed does not exist!' + if (!message || message === 'Breed not found') return 'This breed/sub-breed does not exist!' return { embed: { image: { url: message }, color: 0x654321 }, content: `🐕 ${args[0]} ${args[1]}` @@ -205,7 +205,7 @@ export const handleDog: Command = { const { message } = await (await fetch( `http://dog.ceo/api/breed/${args[0].toLowerCase()}/images/random` )).json() - if (!message) return 'This breed does not exist!' + if (!message || message === 'Breed not found') return 'This breed does not exist!' return { embed: { image: { url: message }, color: 0x654321 }, content: '🐕 ' + args[0] } } catch (err) { return `Something went wrong 👾 Error: ${err}` } }