Skip to content

Commit

Permalink
Fix issues with dog, kick and ban now DM properly.
Browse files Browse the repository at this point in the history
  • Loading branch information
retrixe committed Feb 3, 2019
1 parent 5baae83 commit d8d537f
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 20 deletions.
30 changes: 20 additions & 10 deletions server/bot/commands/admin/ban.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 24 additions & 8 deletions server/bot/commands/admin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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?' }
}
}
Expand All @@ -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') {
Expand Down
4 changes: 2 additions & 2 deletions server/bot/commands/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]}`
Expand All @@ -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}` }
}
Expand Down

0 comments on commit d8d537f

Please sign in to comment.