public void Reset(Chat chat) { lock (_states) { if (_states.ContainsKey(chat.Id)) { var state = new ChatState(); _states[chat.Id] = state; } } }
public void AddMessage(Chat chat) { lock (_states) { if (_states.ContainsKey(chat.Id)) { _states[chat.Id] = ((ChatState)_states[chat.Id]).AddMessage(); return; } var state = new ChatState().AddMessage(); _states.Add(chat.Id, state); } }
public ChatState GetState(Chat chat) { lock (_states) { if (_states.ContainsKey(chat.Id)) { return((ChatState)_states[chat.Id]); } var state = new ChatState(); _states.Add(chat.Id, state); return(state); } }
public ChatState AddSigning(Chat chat, Signing signing) { lock (_states) { if (!_states.ContainsKey(chat.Id)) { var state = new ChatState(); _states.Add(chat.Id, state); } var current = (ChatState)_states[chat.Id]; current = current.AddSigning(signing); _states[chat.Id] = current; return(current); } }
public static string BuildMessage(ChatState state) { var message = ""; string status; var forTwos = state.Signings.Where(_ => _.Twos); var forThrees = state.Signings.Where(_ => _.Threes); var threes = Intervals.FindOverlap(forThrees, 3); var twos = Intervals.FindOverlap(forTwos, 2); if (threes.Item1.Count > 2) { status = ThreesReady; message = message + BuildTimeString(threes.Item2, threes.Item3); message = message + BuildTeam(threes.Item1, true); } else if (twos.Item1.Count > 1) { status = TwosReady; message = message + BuildTimeString(twos.Item2, twos.Item3); message = message + BuildTeam(twos.Item1, true); } else { status = CurrentStatus; if (state.GetTwos().Any()) { message = message + "2v2:\n" + BuildTeam(forTwos, false); } if (state.GetThrees().Any()) { message = message + "3v3:\n" + BuildTeam(forThrees, false); } } return(status + message); }
public void PingParty(ChatState state, Chat chat) { var message = MessageBuilder.BuildMessage(state); SendMessage(chat, message); }