Ask an icebreaker question from a list that can be maintained.
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 package has no README
Usage
icebreaker add [listName] [A question with multiple words] adds the question to the list listName. You don’t need to wrap the question in quotes.
icebreaker list [listName] lists the next few questions in the list listName.
icebreaker ask [listName] ask the next question from the list listName. The question will be removed from the list.
icebreaker printList responds with the lists that have already been created.
Code
public async Task<List<string>> ReadQuestions(string listName)
{
return await Bot.Brain.GetAsAsync(listName, new List<string>());
}
public async Task AddQuestion(string listName, string question)
{
var questions = await ReadQuestions(listName);
questions.Add(question);
await Bot.Brain.WriteAsync(listName, questions);
await Bot.ReplyAsync(
$”Saved the question [{question}] to the list {listName}. There are now {questions.Count} questions left.”);
}
public async Task PushQuestion(string listName, string question)
{
var questions = await ReadQuestions(listName);
questions = questions.Prepend(question).ToList();
await Bot.Brain.WriteAsync(listName, questions);
await Bot.ReplyAsync(
$”Saved the question [{question}] to the list {listName}. There are now {questions.Count} questions left.”);
}
public async Task ListQuestions(string listName)
{
var questions = await ReadQuestions(listName);
await Bot.ReplyAsync($”There are {questions.Count} questions in the list {listName}.”);
if (questions.Any())
{
var sb = new System.Text.StringBuilder();
foreach(var q in questions.Take(5)){
sb.AppendLine(“\t” + q);
}
await Bot.ReplyAsync($”Here’s the next few questions\n{sb}”);
}
}
public async Task AskQuestion(string listName)
{
var questions = await ReadQuestions(listName);
var toAsk = questions
.Take(1)
.FirstOrDefault() ?? “<no more questions>”;
var toSave = questions.Skip(1).ToList();
await Bot.ReplyAsync($”Here’s an Icebreaker for ya:\n\n*{toAsk}*”);
if (toSave.Count < 10)
{
await Bot.ReplyAsync($”There are only {toSave.Count} questions left! Better add some more!”);
}
await Bot.Brain.WriteAsync(listName, toSave);
}
public async Task PrintLists(){
var lists = await Bot.Brain.GetKeysAsync();
var sb = new StringBuilder();
if (lists.Count == 1)
{
sb.AppendLine(“There is one list”);
}
else
{
sb.AppendLine($”There are {lists.Count} lists”);
}
foreach(var list in lists)
{
sb.AppendLine(” ” + list);
}
await Bot.ReplyAsync(sb.ToString());
}
public async Task PrintUsage()
{
await Bot.ReplyAsync(“USAGE:”);
var addUsage = $”*{Bot.SkillName} add [listName] [A question with multiple words]* adds the question to the list listName. You don’t need to wrap the question in quotes.”;
var listUsage = $”*{Bot.SkillName} list [listName]* lists the next few questions in the list listName.”;
var askUsage = $”*{Bot.SkillName} ask [listName]* ask the next question from the list listName. The question will be removed from the list.”;
await Bot.ReplyAsync(addUsage);
await Bot.ReplyAsync(listUsage);
await Bot.ReplyAsync(askUsage);
}
var (c, l, q) = Bot.Arguments;
var command = c.Value.ToLower();
var listName = l.Value;
var question = q.Value;
switch ((command, listName, question)){
case (“”, _, _):
case (“add”, _, “”):
case (“push”, _, “”):
await PrintUsage();
break;
case (“add”, _, _):
await AddQuestion(listName, question);
break;
case (“push”, _, _):
await PushQuestion(listName, question);
break;
case (“list”, _, _):
await ListQuestions(listName);
break;
case (“ask”, _, _):
await AskQuestion(listName);
break;
case (“printlists”, _, _):
await PrintLists();
break;
}