Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private function cmdRoll($message, $args)
- {
- $random = [];
- $response = [];
- $embed = new MessageEmbed();
- $embed
- ->setTitle('Roll some numbers!')
- ->setColor($this->settings['discord']['colors']['grey'])
- ->setTimestamp();
- if (!isset($args[0])) {
- $message->channel
- ->send('', [
- 'embed' => $embed
- ->setColor($this->settings['discord']['colors']['red'])
- ->setDescription('Missing the *range* parameter.'),
- ])
- ->done(
- null,
- function ($e) use ($message, $embed) {
- $this->channelMessageSendError($e, $message->channel, null, $embed);
- }
- );
- return;
- }
- if (strstr($args[0], '-')) {
- list($start, $stop) = explode('-', $args[0]);
- }
- if (isset($args[1])) {
- $rolls = intval($args[1]) ?: 1;
- }
- $start = $start ?? 1;
- $stop = $stop ?? $args[0];
- $rolls = $rolls ?? 1;
- if ($start >= $stop) {
- $message->channel
- ->send('', [
- 'embed' => $embed
- ->setColor($this->settings['discord']['colors']['red'])
- ->setDescription('The *start* digit cannot be higher than the *end* digit of a *range*.'),
- ])
- ->done(
- null,
- function ($e) use ($message, $embed) {
- $this->channelMessageSendError($e, $message->channel, null, $embed);
- }
- );
- return;
- }
- if (($stop - $start) <= $rolls) {
- $message->channel
- ->send('', [
- 'embed' => $embed
- ->setColor($this->settings['discord']['colors']['red'])
- ->setDescription('You cannot have more *rolls* than the *range* would allow.'),
- ])
- ->done(
- null,
- function ($e) use ($message, $embed) {
- $this->channelMessageSendError($e, $message->channel, null, $embed);
- }
- );
- return;
- }
- for ($i = 1; $i <= $rolls; $i++) {
- $selected = false;
- while ($selected === false) {
- $int = random_int($start, $stop);
- if (in_array($int, $random)) {
- continue;
- }
- $selected = $int;
- }
- $random[$i] = $selected;
- }
- foreach ($random as $pos => $int) {
- $response[] = "{$pos}. Rolled *{$int}*";
- }
- $message->channel
- ->send('', [
- 'embed' => $embed
- ->addField('Rolls', implode("\n", $response), false)
- ])
- ->done(
- null,
- function ($e) use ($message, $embed) {
- $this->channelMessageSendError($e, $message->channel, null, $embed);
- }
- );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement