
by LastDragon
Ask an icebreaker question from a list that can be maintained.
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;
}
Version History
Version | Created | Author | Release Notes | Installs |
---|---|---|---|---|
2.3.0 | 3/19/2021 |
![]() Jormungandr |
Adds the |
2 |
2.2.0 | 3/8/2021 |
![]() Jormungandr |
No release notes for this version. | 0 |
2.1.0 | 3/3/2021 |
![]() Jormungandr |
Improved the messaging when adding, asking, or listing questions to signal how many questions are left. |
0 |
2.0.0 | 3/2/2021 |
![]() Jormungandr |
Supports multiple lists. To access questions stored before this version, use the listname i.e., |
0 |
1.0.0 | 2/25/2021 |
![]() Jormungandr |
No release notes for this version. | 0 |
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