private string HandleTodo(SlashCommand message) { var listId = message.channel_id; var list = _todoService.GetItems(message.user_id, listId).ToArray(); var @operator = message.text.SubstringByWords(0, 1); if ([email protected]()) { @operator = @operator.ToLowerInvariant(); } switch (@operator) { case "": { // Just echo the list break; } case "show": { _bus.Publish(new MessageToSlack { channel = listId, text = list.ToSlackString() }); return(null); } case "add": { var todoText = message.text.SubstringByWords(1); if (todoText.Missing()) { return(null); } _todoService.AddItem(message.user_id, listId, todoText); break; } case "tick": { var todoItemId = message.text.SubstringByWords(1, 1); if (todoItemId.Missing()) { return(null); } var force = message.text.SubstringByWords(2, 1).ToLowerInvariant() == "force"; try { _todoService.TickItem(message.user_id, listId, todoItemId, force); } catch (TodoItemClaimedBySomeoneElseException ex) { return(string.Format( "This task is claimed by <@{0}>. Use `/todo {1} {2} force` to override.", ex.UserId, @operator, todoItemId)); } break; } case "untick": { var todoItemId = message.text.SubstringByWords(1, 1); if (todoItemId.Missing()) { return(null); } _todoService.UntickItem(message.user_id, listId, todoItemId); break; } case "remove": { var todoItemId = message.text.SubstringByWords(1, 1); if (todoItemId.Missing()) { return(null); } var force = message.text.SubstringByWords(2, 1).ToLowerInvariant() == "force"; try { _todoService.RemoveItem(message.user_id, listId, todoItemId, force); } catch (TodoItemClaimedBySomeoneElseException ex) { return(string.Format( "This task is claimed by <@{0}>. Use `/todo {1} {2} force` to override.", ex.UserId, @operator, todoItemId)); } break; } case "trim": { _todoService.ClearItems(message.user_id, listId, includeUnticked: false, force: false); break; } case "clear": { var force = message.text.SubstringByWords(1, 1).ToLowerInvariant() == "force"; try { _todoService.ClearItems(message.user_id, listId, includeUnticked: true, force: force); } catch (TodoItemClaimedBySomeoneElseException ex) { return(string.Format( "There are tasks claimed by other people. Use `/todo {0} force` to override.", @operator)); } break; } case "claim": { var todoItemId = message.text.SubstringByWords(1, 1); if (todoItemId.Missing()) { return(null); } var force = message.text.SubstringByWords(2, 1).ToLowerInvariant() == "force"; try { _todoService.ClaimItem(message.user_id, listId, todoItemId, force); } catch (TodoItemClaimedBySomeoneElseException ex) { return(string.Format( "This task is claimed by <@{0}>. Use `/todo {1} {2} force` to override.", ex.UserId, @operator, todoItemId)); } break; } case "free": { var todoItemId = message.text.SubstringByWords(1, 1); if (todoItemId.Missing()) { return(null); } var force = message.text.SubstringByWords(2, 1).ToLowerInvariant() == "force"; try { _todoService.FreeItem(message.user_id, listId, todoItemId, force); } catch (TodoItemClaimedBySomeoneElseException ex) { return(string.Format( "This task is claimed by <@{0}>. Use `/todo {1} {2} force` to override.", ex.UserId, @operator, todoItemId)); } break; } case "help": { return("TODO"); // TODO Return usage info } default: { return("Sorry, that is not a valid syntax for the `/todo` command. Use `/todo help` to see available operations."); } } list = _todoService.GetItems(message.user_id, listId).ToArray(); return(list.ToSlackString()); }