
by Snuggle Chat
Roll Dice!
README
Simple skill for rolling dice.
Will print the resulting sum and all the individual rolls of the dice. Individual rolls will only be shown if the entire message doesn’t exceed 2000 characters.
Usage
@abbot roll 2d20
Number of dice must be greater than 0 and less than 32767.
Number of sides must be greater than 0 and less than 2147483647.
Code
var match = Regex.Match(arg, @”(\d*)d(\d*)”);
if (match.Groups.Count != 3 || !match.Groups[1].Success || !match.Groups[2].Success) {
await Bot.ReplyAsync(“Unable to read dice. Expecting something like 2d20, for rolling two 20-sided dice.”);
return;
}
if (!Int16.TryParse(match.Groups[1].Value, out var numdice) || numdice <= 0) {
await Bot.ReplyAsync($”Number of dice to roll must be larger than 0 and less than {Int16.MaxValue}.”);
return;
}
if (!Int32.TryParse(match.Groups[2].Value, out var numsides) || numsides <= 0) {
await Bot.ReplyAsync($”Number of sides to roll must be larger than 0 and less than {Int32.MaxValue}.”);
return;
}
var randgen = new Random();
var rolls = new int[numdice];
double sum = 0;
for (int i = 0; i < numdice; i++) {
var roll = randgen.Next(numsides) + 1;
rolls[i] = roll;
sum += roll;
}
var rollsstr = String.Join(“,”, rolls);
var output = $”Result: {sum}\nRolls: [{rollsstr}]”;
// Discord has lowest character limit of 2000, so we’ll keep within that.
if (output.Length >= 2000)
output = $”Result: {sum}\nRolls: Exceeds character limit, not showing.”;
await Bot.ReplyAsync(output);
Version History
Version | Created | Author | Release Notes | Installs |
---|---|---|---|---|
1.0.0 | 7/28/2021 |
![]() CapnRat |
Initial release. Time to head to Vegas! |
2 |
You need an account to install this package with Abbot. Signing in with Slack or Discord will create an account if you don’t have one already.
Details
-
Last updated -
Installs - 2 total installs
-
Language - CSharp
-
License - MIT License