Skip to content

Instantly share code, notes, and snippets.

@luuhq
Last active April 10, 2016 06:42
Show Gist options
  • Save luuhq/9688328353691693bf9ecaef56584896 to your computer and use it in GitHub Desktop.
Save luuhq/9688328353691693bf9ecaef56584896 to your computer and use it in GitHub Desktop.
private static Message CreateReplyMessage(Message message, string text)
{
var reply = message.CreateReplyMessage(text);
reply.BotUserData = message.BotUserData;
return reply;
}
private Message HandleAddCommand(Command command, Message message)
{
if (string.IsNullOrWhiteSpace(command.Parameters))
{
return CreateReplyMessage(message, "I need a category to keep tally for. Example: add exercise");
}
var category = command.Parameters.ToLowerInvariant();
var tallies = message.GetBotUserData<Dictionary<string, int>>("tallies");
if (tallies == null)
{
tallies = new Dictionary<string, int>();
}
int tally = 0;
tallies.TryGetValue(category, out tally);
tally += 1;
tallies[category] = tally;
var replyMessage = CreateReplyMessage(message, $"The tally for '{category}' has been updated to {tally}");
// Set the new tally value to the reply message
replyMessage.SetBotUserData("tallies", tallies);
return replyMessage;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment