Last active
April 10, 2016 06:42
-
-
Save luuhq/9688328353691693bf9ecaef56584896 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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