Skip to content

Commit

Permalink
Add /leave from 2.1.2 to v3.
Browse files Browse the repository at this point in the history
  • Loading branch information
retrixe committed May 15, 2018
1 parent 13756b9 commit d1670b2
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 3 deletions.
37 changes: 37 additions & 0 deletions server/bot/commands/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,40 @@ export const handleAvatar: IveBotCommand = (client) => ({
return 'Link: ' + user.avatarURL.split('128').join('') + '2048'
}
})

export const handleLeave: IveBotCommand = (client, db) => ({
opts: {
description: 'Makes you leave the server.',
fullDescription: 'This kicks you from the server, essentially making you leave.',
usage: '/leave',
errorMessage: 'There was an error processing your request.',
guildOnly: true,
argsRequired: false
},
name: 'leave',
generator: (message) => {
if (!db.leave.includes(message.author.id)) {
client.createMessage(
message.channel.id,
'Are you sure you want to leave the server? ' +
'You will require an invite link to join back. Type /leave to confirm.'
)
db.leave.push(message.author.id)
setTimeout(() => {
if (db.leave.findIndex(i => i === message.author.id) === -1) return
client.createMessage(message.channel.id, 'Your leave request has timed out.')
db.leave.splice(db.leave.findIndex(i => i === message.author.id), 1)
}, 30000)
} else if (db.leave.includes(message.author.id)) {
db.leave.splice(db.leave.findIndex(i => i === message.author.id), 1)
client.kickGuildMember(message.member.guild.id, message.author.id, 'Used /leave.')
.then(() => client.createMessage(
message.channel.id,
`${message.author.username}#${message.author.discriminator} has left the server.`
)).catch(() => client.createMessage(
message.channel.id,
'You will have to manually leave the server or transfer ownership before leaving.'
))
}
}
})
3 changes: 2 additions & 1 deletion server/bot/imports/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ export type DB = {
},
link: {
[index: string]: string
}
},
leave: Array<string>
}
export type mongoDB = {
collection: Function
Expand Down
4 changes: 3 additions & 1 deletion server/bot/oldCommands/help.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ let generalHelp = ` ** Jony Ive can do many commands 📡**
TP \`/request\` - Request a specific feature.
\`/token\` - Links your Discord to IveBot Web (use in DM only)
\`/weather\` - It's really cloudy here..
\`/remindme\` - Reminders.
\`/say\` | \`/type\` - Say something, even in another channel.
\`/editLastSay\` - Even if it was another channel.
\`/remindme\` - Reminders.
\`/leave\` - Makes you leave the server.
\`/avatar\` - Avatar of a user.
\`/about\`, \`/ping\`, \`/uptime\` and \`/version\` - About the running instance of IveBot.
\`/giverole\` and \`/takerole\` - Edit roles.
Expand Down Expand Up @@ -126,6 +127,7 @@ const commandDocs: { [index: string]: any } = {
'mute': b('/mute <user by ID/username/mention> (time limit) (reason)', 'Mute someone. Compatible with Dyno.', '/mute voldemort 1h bored'),
'unmute': b('/unmute <user by ID/username/mention> (reason)', 'Unmute someone.', '/unmute voldemort wrong person'),
'weather': b('/weather <city name>(,country name)', 'What\'s the weather like at your place?', '/weather Shanghai,CN', '/wt'),
'leave': b('/leave', 'This kicks you from the server, essentially making you leave.', '/leave'),
'token': b('/token', 'Links your Discord to IveBot Web (use in DM only, or your account may be hacked)', '/token'),
'namemc': b('/namemc <premium Minecraft username>', 'Displays previous usernames and skins of a Minecraft player.', '/namemc voldemort', '/nmc'),
'calculate': b('/calculate <expression>', 'Calculate the value of an expression.', '/calculate 2 + 2', '/calc')
Expand Down
2 changes: 1 addition & 1 deletion server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ client.on('error', (err: string, id: string) => {
})

// Create a database to handle certain stuff.
const tempDB: DB = {gunfight: [], say: {}, link: {}}
const tempDB: DB = {gunfight: [], say: {}, link: {}, leave: []}

// Register all commands in bot/commands onto the CommandClient.
readdir('./server/bot/commands', (err, commandFiles) => {
Expand Down

0 comments on commit d1670b2

Please sign in to comment.