示例#1
0
        public async Task AddEventFake(string eventName, string path, string discription, bool isActive)
        {
            EmbedBuilder eb = new EmbedBuilder();

            //Loaded data
            BinaryEventArray entry = new BinaryEventArray(new BinaryEvent[0]);

            //Load
            EventArray.Load(path, ref entry);
            //Modify
            bool isValidEventName = false;

            for (int i = 0; i < entry.Events.Length; i++)
            {
                if (entry.Events[i].EventName == eventName)
                {
                    if (entry.Events[i].EventType == -1 || entry.Events[i].EventType == 0 || entry.Events[i].EventType == 1)
                    {
                        entry.Events[i].EventType = 0;
                        if (isActive)
                        {
                            entry.Events[i].EventType = 1;
                        }

                        List <BinaryEventSchedule> schedules          = entry.Events[i].Schedules.ToList();
                        BinaryEventSchedule        eventScheduleEntry = new BinaryEventSchedule(discription, "", new long[0], 0);
                        schedules.Add(eventScheduleEntry);

                        entry.Events[i].Schedules = schedules.ToArray();
                        //Save
                        EventArray.Save(path, entry);

                        eb.Title = "**📝 A new schedule has been added to " + eventName + "!**";
                        eb.WithColor(Color.Green);
                    }
                    else
                    {
                        eb.Title = "**🚫 " + eventName + " is a different event type!**";
                        eb.WithColor(Color.Red);
                    }

                    isValidEventName = true;
                    break;
                }
            }

            if (!isValidEventName)
            {
                eb.Title = "**🚫 The event " + eventName + " doesn't exists!**";
                eb.WithColor(Color.Red);
            }

            await Context.Channel.SendMessageAsync("", false, eb.Build());
        }
示例#2
0
        public async Task RemoveEvent(string eventName, string eventListName, string path)
        {
            EmbedBuilder eb = new EmbedBuilder();

            //Loaded data
            BinaryEventArray entry = new BinaryEventArray(new BinaryEvent[0]);

            //Load
            EventArray.Load(path, ref entry);

            bool eventExists = false;

            for (int i = 0; i < entry.Events.Length; i++)
            {
                if (entry.Events[i].EventName == eventName)
                {
                    eventExists = true;
                    break;
                }
            }

            if (eventExists)
            {
                //Modify
                List <BinaryEvent> eventEntries = entry.Events.ToList();
                for (int i = 0; i < eventEntries.Count; i++)
                {
                    if (eventEntries[i].EventName == eventName)
                    {
                        eventEntries.RemoveAt(i);
                        break;
                    }
                }
                entry.Events = eventEntries.ToArray();
                //Save
                EventArray.Save(path, entry);

                eb.Title = "**📁 " + eventName + " has been removed from the " + eventListName + " events list!**";
                eb.WithColor(Color.Green);
            }
            else
            {
                eb.Title = "**🚫 The event " + eventName + " doesn't exists!**";
                eb.WithColor(Color.Red);
            }

            await Context.Channel.SendMessageAsync("", false, eb.Build());
        }
示例#3
0
        public async Task AddEvent(string eventName, string eventListName, string path)
        {
            EmbedBuilder eb = new EmbedBuilder();

            //Loaded data
            BinaryEventArray entry = new BinaryEventArray(new BinaryEvent[0]);

            //Load
            EventArray.Load(path, ref entry);

            bool eventExists = false;

            for (int i = 0; i < entry.Events.Length; i++)
            {
                if (entry.Events[i].EventName == eventName)
                {
                    eventExists = true;
                    break;
                }
            }

            if (!eventExists)
            {
                //Modify
                List <BinaryEvent> eventEntries = entry.Events.ToList();
                BinaryEvent        eventEntry   = new BinaryEvent(eventName, -1, new BinaryEventSchedule[0]);
                eventEntries.Add(eventEntry);
                entry.Events = eventEntries.ToArray();
                //Save
                EventArray.Save(path, entry);

                eb.Title = "**🗓️ " + eventName + " has been added to the " + eventListName + " events list!**";
                eb.WithColor(Color.Green);
            }
            else
            {
                eb.Title = "**🚫 The event " + eventName + " already exists!**";
                eb.WithColor(Color.Red);
            }

            await Context.Channel.SendMessageAsync("", false, eb.Build());
        }
示例#4
0
        public async Task ResetEvent(string eventName, string path)
        {
            EmbedBuilder eb = new EmbedBuilder();

            //Loaded data
            BinaryEventArray entry = new BinaryEventArray(new BinaryEvent[0]);

            //Load
            EventArray.Load(path, ref entry);
            //Modify
            bool isValidEventName = false;

            for (int i = 0; i < entry.Events.Length; i++)
            {
                if (entry.Events[i].EventName == eventName)
                {
                    entry.Events[i].EventType = -1;

                    List <BinaryEventSchedule> schedules = new List <BinaryEventSchedule>();
                    entry.Events[i].Schedules = schedules.ToArray();
                    //Save
                    EventArray.Save(path, entry);

                    eb.Title = "**📝 " + eventName + " has been reset!**";
                    eb.WithColor(Color.Green);

                    isValidEventName = true;
                    break;
                }
            }

            if (!isValidEventName)
            {
                eb.Title = "**🚫 The event " + eventName + " doesn't exists!**";
                eb.WithColor(Color.Red);
            }

            await Context.Channel.SendMessageAsync("", false, eb.Build());
        }
示例#5
0
        public async Task AddEventDate(string eventName, string path, string startingDate, string endingDate, string duration, string[] startTimes)
        {
            EmbedBuilder eb = new EmbedBuilder();

            DateTime parsedStartingDate;
            DateTime parsedEndingDate;
            bool     isValidStartingDate = DateTime.TryParseExact(startingDate, "MM-dd-yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out parsedStartingDate);
            bool     isValidEndingDate   = DateTime.TryParseExact(endingDate, "MM-dd-yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out parsedEndingDate);

            if (parsedStartingDate <= parsedEndingDate)
            {
                if (isValidStartingDate && isValidEndingDate)
                {
                    TimeSpan parsedDuration;
                    bool     isValidDuration = TimeSpan.TryParseExact(duration, "hh':'mm", null, out parsedDuration);

                    if (isValidDuration)
                    {
                        List <TimeSpan> parsedStartTimes  = new List <TimeSpan>();
                        bool            isValidStartTimes = true;
                        for (int i = 0; i < startTimes.Length; i++)
                        {
                            TimeSpan parsedStartTime;
                            if (TimeSpan.TryParseExact(startTimes[i], "hh':'mm", null, out parsedStartTime))
                            {
                                parsedStartTimes.Add(parsedStartTime);
                            }
                            else
                            {
                                isValidStartTimes = false;
                                break;
                            }
                        }
                        parsedStartTimes.Sort();

                        if (isValidStartTimes)
                        {
                            //Loaded data
                            BinaryEventArray entry = new BinaryEventArray(new BinaryEvent[0]);
                            //Load
                            EventArray.Load(path, ref entry);
                            //Modify
                            bool isValidEventName = false;
                            for (int i = 0; i < entry.Events.Length; i++)
                            {
                                if (entry.Events[i].EventName == eventName)
                                {
                                    if (entry.Events[i].EventType == -1 || entry.Events[i].EventType == 3)
                                    {
                                        entry.Events[i].EventType = 3;

                                        List <long> StartTimeTicks = new List <long>();
                                        for (int j = 0; j < parsedStartTimes.Count; j++)
                                        {
                                            StartTimeTicks.Add(parsedStartTimes[j].Ticks);
                                        }

                                        List <BinaryEventSchedule> schedules          = entry.Events[i].Schedules.ToList();
                                        BinaryEventSchedule        eventScheduleEntry = new BinaryEventSchedule(startingDate, endingDate, StartTimeTicks.ToArray(), parsedDuration.Ticks);
                                        schedules.Add(eventScheduleEntry);

                                        entry.Events[i].Schedules = schedules.ToArray();
                                        //Save
                                        EventArray.Save(path, entry);

                                        eb.Title = "**📝 A new schedule has been added to " + eventName + "!**";
                                        eb.WithColor(Color.Green);
                                    }
                                    else
                                    {
                                        eb.Title = "**🚫 " + eventName + " is a different event type!**";
                                        eb.WithColor(Color.Red);
                                    }

                                    isValidEventName = true;
                                    break;
                                }
                            }

                            if (!isValidEventName)
                            {
                                eb.Title = "**🚫 The event " + eventName + " doesn't exists!**";
                                eb.WithColor(Color.Red);
                            }
                        }
                        else
                        {
                            eb.Title = "**🚫 Invalid Start Times!**";
                            eb.WithColor(Color.Red);
                        }
                    }
                    else
                    {
                        eb.Title = "**🚫 Invalid duration!**";
                        eb.WithColor(Color.Red);
                    }
                }
                else
                {
                    eb.Title = "**🚫 Invalid date!**";
                    eb.WithColor(Color.Red);
                }
            }
            else
            {
                eb.Title = "**🚫 Starting date must be earlier or equal to ending date!**";
                eb.WithColor(Color.Red);
            }
            await Context.Channel.SendMessageAsync("", false, eb.Build());
        }
示例#6
0
        public async Task AddEventDaily(string eventName, string path, string startingDay, string endingDay, string duration, string[] startTimes)
        {
            EmbedBuilder eb = new EmbedBuilder();

            //Checks if the day string passed in is a valid value
            string[] dayNames           = Enum.GetNames(typeof(DayOfWeek));
            bool     isValidStartingDay = dayNames.Contains(startingDay, StringComparer.InvariantCultureIgnoreCase);
            bool     isValidEndingDay   = dayNames.Contains(endingDay, StringComparer.InvariantCultureIgnoreCase);

            if (isValidStartingDay && isValidEndingDay)
            {
                TimeSpan parsedDuration;
                bool     isValidDuration = TimeSpan.TryParseExact(duration, "hh':'mm", null, out parsedDuration);

                if (isValidDuration)
                {
                    List <TimeSpan> parsedStartTimes  = new List <TimeSpan>();
                    bool            isValidStartTimes = true;
                    for (int i = 0; i < startTimes.Length; i++)
                    {
                        TimeSpan parsedStartTime;
                        if (TimeSpan.TryParseExact(startTimes[i], "hh':'mm", null, out parsedStartTime))
                        {
                            parsedStartTimes.Add(parsedStartTime);
                        }
                        else
                        {
                            isValidStartTimes = false;
                            break;
                        }
                    }
                    parsedStartTimes.Sort();

                    if (isValidStartTimes)
                    {
                        //Loaded data
                        BinaryEventArray entry = new BinaryEventArray(new BinaryEvent[0]);
                        //Load
                        EventArray.Load(path, ref entry);
                        //Modify
                        bool isValidEventName = false;
                        for (int i = 0; i < entry.Events.Length; i++)
                        {
                            if (entry.Events[i].EventName == eventName)
                            {
                                if (entry.Events[i].EventType == -1 || entry.Events[i].EventType == 2)
                                {
                                    entry.Events[i].EventType = 2;

                                    List <long> StartTimeTicks = new List <long>();
                                    for (int j = 0; j < parsedStartTimes.Count; j++)
                                    {
                                        StartTimeTicks.Add(parsedStartTimes[j].Ticks);
                                    }

                                    List <BinaryEventSchedule> schedules          = entry.Events[i].Schedules.ToList();
                                    BinaryEventSchedule        eventScheduleEntry = new BinaryEventSchedule(startingDay, endingDay, StartTimeTicks.ToArray(), parsedDuration.Ticks);
                                    schedules.Add(eventScheduleEntry);

                                    entry.Events[i].Schedules = schedules.ToArray();
                                    //Save
                                    EventArray.Save(path, entry);

                                    eb.Title = "**📝 A new schedule has been added to " + eventName + "!**";
                                    eb.WithColor(Color.Green);
                                }
                                else
                                {
                                    eb.Title = "**🚫 " + eventName + " is a different event type!**";
                                    eb.WithColor(Color.Red);
                                }

                                isValidEventName = true;
                                break;
                            }
                        }

                        if (!isValidEventName)
                        {
                            eb.Title = "**🚫 The event " + eventName + " doesn't exists!**";
                            eb.WithColor(Color.Red);
                        }
                    }
                    else
                    {
                        eb.Title = "**🚫 Invalid Start Times!**";
                        eb.WithColor(Color.Red);
                    }
                }
                else
                {
                    eb.Title = "**🚫 Invalid duration!**";
                    eb.WithColor(Color.Red);
                }
            }
            else
            {
                eb.Title = "**🚫 Invalid day!**";
                eb.WithColor(Color.Red);
            }

            await Context.Channel.SendMessageAsync("", false, eb.Build());
        }
示例#7
0
        static async Task UpdateTimers()
        {
            //Loaded data
            BinaryHouseNormal houseEntry         = new BinaryHouseNormal(0, 0, 0);
            BinaryEventArray  generalEventsEntry = new BinaryEventArray(new BinaryEvent[0]);
            BinaryEventArray  cbInfoEventsEntry  = new BinaryEventArray(new BinaryEvent[0]);
            BinaryEventArray  cbGenEventsEntry   = new BinaryEventArray(new BinaryEvent[0]);
            BinaryEventArray  cbSpecEventsEntry  = new BinaryEventArray(new BinaryEvent[0]);
            ulong             pointsDynamicID    = 0;
            ulong             eventsDynamicID    = 0;
            ulong             serverDynamicID    = 0;

            //Load
            HouseNormal.Load(Setup.HousePath, ref houseEntry);
            EventArray.Load(Setup.GeneralEventsPath, ref generalEventsEntry);
            EventArray.Load(Setup.CBInfoEventsPath, ref cbInfoEventsEntry);
            EventArray.Load(Setup.CBGenEventsPath, ref cbGenEventsEntry);
            EventArray.Load(Setup.CBSpecEventsPath, ref cbSpecEventsEntry);
            ULongNormal.Load(Setup.PointsDynamicIDPath, ref pointsDynamicID);
            ULongNormal.Load(Setup.EventsDynamicIDPath, ref eventsDynamicID);
            ULongNormal.Load(Setup.ServerDynamicIDPath, ref serverDynamicID);

            IMessage pointsMessage = await Setup.Client.GetGuild(Setup.ApeGangGuildID).GetTextChannel(Setup.TimerChannelID).GetMessageAsync(pointsDynamicID);

            IMessage eventsMessage = await Setup.Client.GetGuild(Setup.ApeGangGuildID).GetTextChannel(Setup.TimerChannelID).GetMessageAsync(eventsDynamicID);

            IMessage serverMessage = await Setup.Client.GetGuild(Setup.ApeGangGuildID).GetTextChannel(Setup.TimerChannelID).GetMessageAsync(serverDynamicID);

            List <IEmbed> pointsEmbeds = pointsMessage.Embeds.ToList();
            List <IEmbed> eventsEmbeds = eventsMessage.Embeds.ToList();
            List <IEmbed> serverEmbeds = serverMessage.Embeds.ToList();

            EmbedBuilder pointsEB = pointsEmbeds[0].ToEmbedBuilder();
            EmbedBuilder eventsEB = eventsEmbeds[0].ToEmbedBuilder();
            EmbedBuilder serverEB = serverEmbeds[0].ToEmbedBuilder();

            //points
            for (int i = 0; i < pointsEB.Fields.Count; i++)
            {
                if (pointsEB.Fields[i].Name == Setup.GorillaEmoji + "House of Gorilla")
                {
                    pointsEB.Fields[i].WithValue("`" + houseEntry.GorillaPoints + " Points`");
                }
                else if (pointsEB.Fields[i].Name == Setup.MonkeyEmoji + "House of Monkey")
                {
                    pointsEB.Fields[i].WithValue("`" + houseEntry.MonkeyPoints + " Points`");
                }
                else if (pointsEB.Fields[i].Name == Setup.BaboonEmoji + "House of Baboon")
                {
                    pointsEB.Fields[i].WithValue("`" + houseEntry.BaboonPoints + " Points`");
                }
            }

            //events
            //Splits the events into two category
            bool          saveEventsEntry = false;
            List <string> eventsInactive  = new List <string>();
            List <string> eventsActive    = new List <string>();

            TimeCalculation(ref generalEventsEntry, ref eventsInactive, ref eventsActive, ref saveEventsEntry);
            //Save
            if (saveEventsEntry)
            {
                EventArray.Save(Setup.GeneralEventsPath, generalEventsEntry);
            }

            for (int i = 0; i < eventsEB.Fields.Count; i++)
            {
                string fieldText = "";
                if (eventsEB.Fields[i].Name == "Events")
                {
                    if (eventsInactive.Count == 0)
                    {
                        fieldText = "`None`";
                    }
                    for (int j = 0; j < eventsInactive.Count; j++)
                    {
                        fieldText += "`" + eventsInactive[j] + "`" + "\n";
                    }
                    eventsEB.Fields[i].WithValue(fieldText);
                }
                else if (eventsEB.Fields[i].Name == "Active events")
                {
                    if (eventsActive.Count == 0)
                    {
                        fieldText = "`None`";
                    }
                    for (int j = 0; j < eventsActive.Count; j++)
                    {
                        fieldText += "`" + eventsActive[j] + "`" + "\n";
                    }
                    eventsEB.Fields[i].WithValue(fieldText);
                }
            }

            //server
            bool          saveCBInfoEntry = false;
            bool          saveCBGenEntry  = false;
            bool          saveCBSpecEntry = false;
            List <string> CBInfoInactive  = new List <string>();
            List <string> CBInfoActive    = new List <string>();
            List <string> CBGenInactive   = new List <string>();
            List <string> CBGenActive     = new List <string>();
            List <string> CBSpecInactive  = new List <string>();
            List <string> CBSpecActive    = new List <string>();

            TimeCalculation(ref cbInfoEventsEntry, ref CBInfoInactive, ref CBInfoActive, ref saveCBInfoEntry);
            TimeCalculation(ref cbGenEventsEntry, ref CBGenInactive, ref CBGenActive, ref saveCBGenEntry);
            TimeCalculation(ref cbSpecEventsEntry, ref CBSpecInactive, ref CBSpecActive, ref saveCBSpecEntry);
            //Save
            if (saveCBInfoEntry)
            {
                EventArray.Save(Setup.CBInfoEventsPath, cbInfoEventsEntry);
            }
            if (saveCBGenEntry)
            {
                EventArray.Save(Setup.CBGenEventsPath, cbGenEventsEntry);
            }
            if (saveCBSpecEntry)
            {
                EventArray.Save(Setup.CBSpecEventsPath, cbSpecEventsEntry);
            }

            string serverText = "`Server time: " + DateTimeOffset.Now.ToOffset(Setup.CurrentTimeZone.BaseUtcOffset).ToString("HH:mm:ss (M/dd/yyyy)") + "`" + "\n";

            for (int j = 0; j < CBInfoInactive.Count; j++)
            {
                serverText += "`" + CBInfoInactive[j] + "`" + "\n";
            }
            for (int j = 0; j < CBInfoActive.Count; j++)
            {
                serverText += "`" + CBInfoActive[j] + "`" + "\n";
            }
            serverEB.WithDescription(serverText);

            for (int i = 0; i < serverEB.Fields.Count; i++)
            {
                string fieldText = "";
                if (serverEB.Fields[i].Name == "General events")
                {
                    if (CBGenInactive.Count == 0)
                    {
                        fieldText = "`None`";
                    }
                    for (int j = 0; j < CBGenInactive.Count; j++)
                    {
                        fieldText += "`" + CBGenInactive[j] + "`" + "\n";
                    }
                    serverEB.Fields[i].WithValue(fieldText);
                }
                else if (serverEB.Fields[i].Name == "Active general events")
                {
                    if (CBGenActive.Count == 0)
                    {
                        fieldText = "`None`";
                    }
                    for (int j = 0; j < CBGenActive.Count; j++)
                    {
                        fieldText += "`" + CBGenActive[j] + "`" + "\n";
                    }
                    serverEB.Fields[i].WithValue(fieldText);
                }
                else if (serverEB.Fields[i].Name == "Special events")
                {
                    if (CBSpecInactive.Count == 0)
                    {
                        fieldText = "`None`";
                    }
                    for (int j = 0; j < CBSpecInactive.Count; j++)
                    {
                        fieldText += "`" + CBSpecInactive[j] + "`" + "\n";
                    }
                    serverEB.Fields[i].WithValue(fieldText);
                }
                else if (serverEB.Fields[i].Name == "Active special events")
                {
                    if (CBSpecActive.Count == 0)
                    {
                        fieldText = "`None`";
                    }
                    for (int j = 0; j < CBSpecActive.Count; j++)
                    {
                        fieldText += "`" + CBSpecActive[j] + "`" + "\n";
                    }
                    serverEB.Fields[i].WithValue(fieldText);
                }
            }

            await(pointsMessage as IUserMessage).ModifyAsync(msg =>
            {
                msg.Embed = pointsEB.Build();
            });

            await(eventsMessage as IUserMessage).ModifyAsync(msg =>
            {
                msg.Embed = eventsEB.Build();
            });

            await(serverMessage as IUserMessage).ModifyAsync(msg =>
            {
                msg.Embed = serverEB.Build();
            });
        }