async Task Specific(CommandContext commandContext) { var topic = await _slackApiService.GetChannelTopic(commandContext.ChannelName); var train = Train.Parse(topic); var targetUser = await _slackApiService.GetUserFromId(commandContext.Arguments); if (train.IsEmpty) { await _slackApiService.PostMessage(commandContext.ChannelName, $"{commandContext.UserName}: {targetUser} isn't on the train."); return; } var rider = train.Carriages[0].Riders.FirstOrDefault(r => r.Name == targetUser); if (rider == null) { await _slackApiService.PostMessage(commandContext.ChannelName, $"{commandContext.UserName}: {targetUser} isn't up yet."); return; } if (rider.Flairs.Flairs.Contains(RiderFlair.Ready) || rider.Flairs.Flairs.Contains(RiderFlair.EverReady)) { await _slackApiService.PostMessage(commandContext.ChannelName, $"{commandContext.UserName}: {targetUser} is already ready."); return; } if (_carriageManipulationService.IsPhaseUnknown(train.Phase)) { await _slackApiService.PostMessage(commandContext.ChannelName, $"{commandContext.UserName}: Uh, I don't know what phase this is...Can you fix it?"); return; } if (_carriageManipulationService.IsNotHeld(train, rider)) { await _slackApiService.PostMessage(commandContext.ChannelName, $"{commandContext.UserName}: Train is held! Can't continue."); return; } rider.Flairs.Flairs.Add(RiderFlair.Ready); await _carriageManipulationService.AdvanceCarriageIfNecessary(train, commandContext.ChannelName); }
public async Task HandleMessage(CommandContext commandContext) { var topic = await _slackApiService.GetChannelTopic(commandContext.ChannelName); var train = Train.Parse(topic); var rider = train.Carriages[0].Riders.FirstOrDefault(r => r.Name == commandContext.UserName); if (rider == null) { await _slackApiService.PostMessage(commandContext.ChannelName, $"{commandContext.UserName}: You're not on this carriage."); return; } if (rider.Flairs.Flairs.Contains(RiderFlair.EverReady)) { await _slackApiService.PostMessage(commandContext.ChannelName, $"{commandContext.UserName}: You're already everyready."); return; } if (_carriageManipulationService.IsPhaseUnknown(train.Phase)) { await _slackApiService.PostMessage(commandContext.ChannelName, $"{commandContext.UserName}: Uh, I don't know what phase this is...Can you fix it?"); return; } if (train.Carriages[0].Riders.IndexOf(rider) == 0) { await _slackApiService.PostMessage(commandContext.ChannelName, $"{commandContext.UserName}: The driver can't everready -- they're in charge of making sure everything is working"); return; } if (_carriageManipulationService.IsNotHeld(train, rider)) { await _slackApiService.PostMessage(commandContext.ChannelName, $"{commandContext.UserName}: Train is held! Can't continue."); return; } // everready replaces ready if (rider.Flairs.Flairs.Contains(RiderFlair.Ready)) { rider.Flairs.Flairs.Remove(RiderFlair.Ready); } rider.Flairs.Flairs.Add(RiderFlair.EverReady); await _carriageManipulationService.AdvanceCarriageIfNecessary(train, commandContext.ChannelName); }