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
This is a skill for giving your friends and colleagues ✨!
Code
if (userArg is not IMentionArgument and {Value: “leaders”} or {Value: “leaderboard”}) {
// @abbot sparkle leaders
var allSparkles = await Bot.Brain.GetAllAsync();
var leaders = allSparkles.ToDictionary(
item => item.Key,
item => (item.Value as List<Sparkle>).Count)
.OrderByDescending(kvp => kvp.Value)
.Take(10)
.Select(kvp => $”{kvp.Key} with {kvp.Value} :sparkles:s”)
.ToMarkdownList();
await Bot.ReplyAsync(leaders);
return;
}
if (userArg is IMentionArgument mention) {
// @abbot sparkle @pmn
if (reasonArg is IMissingArgument) {
await SparkleAsync(mention.Mentioned, Bot.From, Bot.Room);
await Bot.ReplyAsync($”{mention.Mentioned} gets a :sparkles:!”);
return;
}
else {
// @abbot sparkle @pmn for being swell
if (reasonArg is IArguments reasonWords) {
if (reasonWords[0] is {Value: “for”}) {
(_, reasonWords) = reasonWords.Pop();
}
reasonArg = reasonWords;
}
await SparkleAsync(mention.Mentioned, Bot.From, Bot.Room, reasonArg.Value);
await Bot.ReplyAsync($”{mention.Mentioned} gets a :sparkles: for {reasonArg.Value}!”);
return;
}
}
if (userArg is {Value: “for”}) {
var sparklee = reasonArg is IMentionArgument user
? user.Mentioned
: reasonArg is {Value: “me”}
? Bot.From
: null;
if (sparklee is not null) {
var sparkles = await GetSparklesAsync(sparklee);
var sparkleList = sparkles.Select(FormatSparkle).ToMarkdownList();
await Bot.ReplyAsync($”:sparkles: Here’s who sparkled {sparklee} :sparkles:\n{sparkleList}”);
return;
}
}
// If we get here, Abbot didn’t understand what the user is trying to do.
await Bot.ReplyAsync($”Sorry, I didn’t understand that. `{Bot} help sparkle` to learn how to sparkle.”);
public class Sparkle {
// The one who sparkes
public string Sparkler { get; set; }
// The reason for which one is sparkled.
public string Reason { get; set; }
// The room in which one is sparkled.
public string Room { get; set; }
// The date (more or less) at which one is sparkled
public DateTime When { get; set; }
}
async Task SparkleAsync(
IChatUser sparklee,
IChatUser sparkler,
IRoom room,
string reason = null)
{
var sparkles = await GetSparklesAsync(sparklee);
var sparkle = new Sparkle {
Sparkler = sparkler.ToString(),
Reason = reason,
Room = room.Name,
When = DateTime.Now
};
sparkles.Add(sparkle);
await Bot.Brain.WriteAsync(sparklee.ToString(), sparkles);
}
async Task<List<Sparkle>> GetSparklesAsync(IChatUser sparklee) {
return await Bot.Brain.GetAsAsync<List<Sparkle>>(sparklee.ToString())
?? new List<Sparkle>();
}
string FormatSparkle(Sparkle sparkle) {
var reason = sparkle.Reason is {Length: > 0}
? sparkle.Reason
: “no reason in particular”;
return $”:sparkles: from {sparkle.Sparkler} for {reason}”;
}