Ejemplo n.º 1
0
        public static void PostChore(Chore chore, string botId, GroupMeChoreDetail choreDetail, GroupMeGroup group = null)
        {
            // Only get group info if we need it to @mention
            if (group == null && choreDetail.HasFlag(GroupMeChoreDetail.CurrentUserMention))
            {
                group = GetGroupInfo(CloudConfigurationManager.GetSetting("GroupMeGroupId"));
            }

            // Not "None"
            if (choreDetail != 0)
            {
                string text = String.Empty;
                // Use Name
                if (choreDetail.HasFlag(GroupMeChoreDetail.Name))
                {
                    text += chore.Name;

                    // Use Description
                    if (choreDetail.HasFlag(GroupMeChoreDetail.Description))
                    {
                        // Use Current User
                        if (choreDetail.HasFlag(GroupMeChoreDetail.CurrentUser))
                        {
                            text += " (" + chore.User.UserName + ")";
                        }
                        // Use Current User w/ mentioning
                        if (choreDetail.HasFlag(GroupMeChoreDetail.CurrentUserMention) && group != null)
                        {
                            var groupMeUser = group.members.SingleOrDefault(t => t.user_id == chore.User.GroupMeId);
                            if (groupMeUser == null)
                            {
                                text += " - @" + chore.User.UserName;
                            }
                            else
                            {
                                text += " - @" + groupMeUser.nickname;
                            }
                        }
                        text += " - " + chore.Description;
                    }
                    // Don't use Description
                    else
                    {
                        // Use Current User
                        if (choreDetail.HasFlag(GroupMeChoreDetail.CurrentUser))
                        {
                            text += " - " + chore.User.UserName;
                        }
                        // Use Current User w/ mentioning
                        if (choreDetail.HasFlag(GroupMeChoreDetail.CurrentUserMention) && group != null)
                        {
                            var groupMeUser = group.members.SingleOrDefault(t => t.user_id == chore.User.GroupMeId);
                            if (groupMeUser == null)
                            {
                                text += " - @" + chore.User.UserName;
                            }
                            else
                            {
                                text += " - @" + groupMeUser.nickname;
                            }
                        }
                    }
                }
                // Use Current User with or without mentioning
                else if (choreDetail.HasFlag(GroupMeChoreDetail.CurrentUser) || choreDetail.HasFlag(GroupMeChoreDetail.CurrentUserMention))
                {
                    // Use Current User
                    if (choreDetail.HasFlag(GroupMeChoreDetail.CurrentUser))
                    {
                        text += chore.User.UserName;
                    }
                    // Use Current User w/ mentioning
                    if (choreDetail.HasFlag(GroupMeChoreDetail.CurrentUserMention) && group != null)
                    {
                        var groupMeUser = group.members.Single(t => t.id == chore.User.GroupMeId);
                        text += "@" + groupMeUser.nickname;
                    }
                    // Use Description
                    if (choreDetail.HasFlag(GroupMeChoreDetail.Description))
                    {
                        text += ": " + chore.Description;
                    }
                }
                // Use Description only
                else
                {
                    text += chore.Description;
                }

                BotPost(botId, text);
            }
        }
Ejemplo n.º 2
0
        public static void PostChoreGroup(ChoreGroup choreGroup, string botId, GroupMeChoreGroupDetail choreGroupDetail, GroupMeChoreDetail choreDetail)
        {
            GroupMeGroup group = null;

            // Only get group info if we need it to @mention
            if (choreDetail.HasFlag(GroupMeChoreDetail.CurrentUserMention))
            {
                group = GetGroupInfo(CloudConfigurationManager.GetSetting("GroupMeGroupId"));
            }

            // Not "None"
            if (choreGroupDetail != 0)
            {
                string text = String.Empty;
                // Use Name
                if (choreGroupDetail.HasFlag(GroupMeChoreGroupDetail.Name))
                {
                    text += choreGroup.Name;

                    // Padding at end
                    if (choreGroupDetail.HasFlag(GroupMeChoreGroupDetail.Schedule) ||
                        choreGroupDetail.HasFlag(GroupMeChoreGroupDetail.ScheduleDates) ||
                        choreGroupDetail.HasFlag(GroupMeChoreGroupDetail.ListChoreNames))
                    {
                        text += " - ";
                    }
                }

                // Use Schedule
                if (choreGroupDetail.HasFlag(GroupMeChoreGroupDetail.Schedule))
                {
                    text += "Every " + choreGroup.RecurrenceCount + " " + choreGroup.RecurrenceDatePart;
                    if (choreGroup.RecurrenceCount > 1)
                    {
                        text += "s";
                    }

                    if (!String.IsNullOrEmpty(choreGroup.SkipDatePart))
                    {
                        text += ", skipping " + choreGroup.SkipCount + " " + choreGroup.SkipDatePart;
                        if (choreGroup.SkipCount > 1)
                        {
                            text += "s";
                        }
                        text += " in between";
                    }

                    // Padding at end
                    if (choreGroupDetail.HasFlag(GroupMeChoreGroupDetail.ScheduleDates) ||
                        choreGroupDetail.HasFlag(GroupMeChoreGroupDetail.ListChoreNames))
                    {
                        text += " - ";
                    }
                }

                // Use Schedule Dates
                if (choreGroupDetail.HasFlag(GroupMeChoreGroupDetail.ScheduleDates))
                {
                    text += choreGroup.CurrentRecurrenceStart.ToShortDateString();
                    text += " to " + choreGroup.CurrentRecurrenceEnd.ToShortDateString();

                    // Padding at end
                    if (choreGroupDetail.HasFlag(GroupMeChoreGroupDetail.ListChoreNames))
                    {
                        text += " - ";
                    }
                }

                // List chore names in header
                if (choreGroupDetail.HasFlag(GroupMeChoreGroupDetail.ListChoreNames))
                {
                    foreach (var chore in choreGroup.Chores)
                    {
                        text += chore.Name + ", ";
                    }
                    text = text.Substring(0, text.Length - 2); // remove final comma and space
                }

                // Post header message
                if (!String.IsNullOrEmpty(text))
                {
                    BotPost(botId, text);
                }
            }

            // Post message for each chore
            foreach (var chore in choreGroup.Chores)
            {
                PostChore(chore, botId, choreDetail, group);
            }
        }