コード例 #1
0
        private List <WaterMember> GetWaterMembersListBasedInLastBotMsgInGroup(string groupdId)
        {
            var lastMsg = GetTodayLastBotMessageInGroup(groupdId);

            if (lastMsg == null)
            {
                return(new List <WaterMember>());
            }

            string[] splitedLastMsg = lastMsg.Split(new string[] { endLineMark }, StringSplitOptions.RemoveEmptyEntries);

            Members = new List <WaterMember>();

            foreach (var msgLine in splitedLastMsg)
            {
                var splitedNameAndQuantity = msgLine.Split(new string[] { ":" }, 2, StringSplitOptions.RemoveEmptyEntries);
                if (splitedNameAndQuantity.Count() < 2)
                {
                    continue;
                }

                var name   = splitedNameAndQuantity.First();
                var bottle = Regex.Matches(splitedNameAndQuantity[1], EmoctionsEnum.Bottle).Count;
                var glass  = Regex.Matches(splitedNameAndQuantity[1], EmoctionsEnum.Glass).Count;

                var member = new WaterMember(name);
                member.BottleCount = bottle;
                member.GlassCount  = glass;

                Members.Add(member);
            }


            return(Members);
        }
コード例 #2
0
        private WaterMember GetSenderMember(SlackMessage slackMessage)
        {
            if (Members == null)
            {
                Members = GetWaterMembersListBasedInLastBotMsgInGroup(slackMessage.ChannelID);
            }

            var member = Members.FirstOrDefault(x => string.Equals(x.Name, slackMessage.User.Name, StringComparison.OrdinalIgnoreCase));

            if (member == null)
            {
                member = new WaterMember(slackMessage.User.Name);
                Members.Add(member);
            }

            return(member);
        }