About Abbot
Abbot is a programmable bot that turns your team chat into a shared command center. We handle all the boilerplate of building and running these conmmands so that you can focus on making tools that help you ship faster.
We built Abbot because we saw the power of this style of work (called ChatOps), when we worked at GitHub. ChatOps made it possible for GitHub to work productively without meetings, while globally distributed. We think it’s a pretty great way to work, so we made it easy to use in Slack, Discord, and Microsoft Teams.
You can read more about Abbot here, check out our blog, or take a look at some of the other cool packages available as a one-click install from Abbot’s Package Directory.
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);