public async Task <Message> Respond(Message message) { var command = string.Join("", message.MessageParts.Skip(1).Select(x => x.Text)).Trim().Remove(0, 4).Trim(); var commandWords = command.Split(' ').Where(x => !string.IsNullOrWhiteSpace(x)).ToList(); if (commandWords.Count < 2) { return(new Message { Text = $"Please specify a command. Possible values are {string.Join(", ", ConfigActions.All())}." }); } string newMessage; switch (commandWords[1]) { case ConfigActions.Get: newMessage = GetStringConfig(); break; case ConfigActions.Add: newMessage = await AddStringConfig(commandWords).ConfigureAwait(false); break; case ConfigActions.Delete: newMessage = await DeleteStringConfig(commandWords).ConfigureAwait(false); break; default: newMessage = $"Invalid string config command. Possible values are {string.Join(", ", ConfigActions.All())}."; break; } return(new Message { Text = newMessage }); }
public void ItShouldDisplayAMessageIfAnInvalidConfigActionIsProvided() { this.Given(x => GivenAStringConfigMessage("invalid")) .When(x => WhenRespondIsCalled()) .Then(x => ItShouldDisplayAMessage($"Invalid string config command. Possible values are {string.Join(", ", ConfigActions.All())}.")) .BDDfy(); }
private string CreateStringConfigHelpMessage(PockyUser user) { if (HasPermission(user, new[] { Role.Admin, Role.Config })) { return("### How to configure string config values 🎻!\n" + $"1. To get/add/delete string config values, type `@{_pockyBotSettings.BotName} {Commands.StringConfig} {string.Join("|",ConfigActions.All())} {{name}} {{value}}`\n" + $" * Example 1: To add a keyword called \"amazing\", type `@{_pockyBotSettings.BotName} {Commands.StringConfig} {ConfigActions.Add} keyword amazing`\n" + $" * Example 2: To add a linked keyword called \"awesome\" to the \"amazing\" keyword, type `@{_pockyBotSettings.BotName} {Commands.StringConfig} {ConfigActions.Add} linkedKeyword amazing:awesome`\n" + "1. I will respond in the room you messaged me in."); } return(CreateDefaultHelpMessage()); }
public void ItShouldDisplayAMessageIfAConfigActionIsNotProvided() { this.Given(x => GivenAStringConfigMessage("")) .When(x => WhenRespondIsCalled()) .Then(x => ItShouldDisplayAMessage($"Please specify a command. Possible values are {string.Join(", ", ConfigActions.All())}.")) .BDDfy(); }