Ejemplo n.º 1
0
 public void Reset(Chat chat)
 {
     lock (_states)
     {
         if (_states.ContainsKey(chat.Id))
         {
             var state = new ChatState();
             _states[chat.Id] = state;
         }
     }
 }
Ejemplo n.º 2
0
        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);
            }
        }
Ejemplo n.º 3
0
        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);
            }
        }
Ejemplo n.º 4
0
        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);
            }
        }
Ejemplo n.º 5
0
        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);
        }
Ejemplo n.º 6
0
        public void PingParty(ChatState state, Chat chat)
        {
            var message = MessageBuilder.BuildMessage(state);

            SendMessage(chat, message);
        }