-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add commands to generate random numbers and flip coins
- Loading branch information
Showing
2 changed files
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!') | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | ||
} | ||
} |