Skip to content

Commit

Permalink
Add commands to generate random numbers and flip coins
Browse files Browse the repository at this point in the history
  • Loading branch information
tgoins committed Aug 7, 2021
1 parent 3b20899 commit 10f3ba9
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/bot/commands/games/coin-flip.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { CommandoMessage } from 'discord.js-commando'
import { Command } from '../../base'
import { Client } from '../../models'

export default class DiceRollCommand extends Command {
constructor(client: Client) {
super(client, {
name: 'flip',
group: 'games',
memberName: 'flip',
description: 'Flip a coin.',
guildOnly: false,
throttling: {
usages: 2,
duration: 3
},
})
}

public async run(msg: CommandoMessage) {
return msg.reply(Math.floor(Math.random() * 10) % 2 == 0 ? 'Heads!' : 'Tails!')
}
}
36 changes: 36 additions & 0 deletions src/bot/commands/games/rng.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { CommandoMessage } from 'discord.js-commando'
import { Command } from '../../base'
import { Client } from '../../models'

export default class RngCommand extends Command {
constructor(client: Client) {
super(client, {
name: 'rng',
group: 'games',
memberName: 'rng',
description: 'Generate a random positive integer.',
guildOnly: false,
throttling: {
usages: 2,
duration: 3
},
args: [
{
key: 'max',
prompt: 'What is the highest number to generate?\n',
type: 'integer'
}
]
})
}

public async run(msg: CommandoMessage, args: {max: number}) {
if (args.max < 1) {
return msg.reply(
'The max must be greater than 0.'
)
}

return msg.reply(Math.floor(Math.random() * args.max))
}
}

0 comments on commit 10f3ba9

Please sign in to comment.