Пример #1
0
        public async Task HouseReset()
        {
            //Roles with access
            List <string> roles = new List <string>();

            roles.Add(Setup.ApeChieftainRole);

            if (await Tools.RolesCheck(Context, roles, true, roles[0]))
            {
                //Loaded data
                BinaryHouseNormal entry = new BinaryHouseNormal(0, 0, 0);
                //Load
                HouseNormal.Load(Setup.HousePath, ref entry);
                //Modify
                entry.GorillaPoints = 0;
                entry.MonkeyPoints  = 0;
                entry.BaboonPoints  = 0;
                //Save
                HouseNormal.Save(Setup.HousePath, entry);

                await AnnounceResetToHouse(Context, Setup.GorillaWebhookClient, entry.GorillaPoints);
                await AnnounceResetToHouse(Context, Setup.MonkeyWebhookClient, entry.MonkeyPoints);
                await AnnounceResetToHouse(Context, Setup.BaboonWebhookClient, entry.BaboonPoints);
            }
            await Context.Message.DeleteAsync();
        }
Пример #2
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();
            });
        }
Пример #3
0
        public static async Task HouseApprove(SocketReaction emoji, int amount)
        {
            SocketGuildUser user             = emoji.User.Value as SocketGuildUser;
            IRole           apeChieftainRole = (user as IGuildUser).Guild.Roles.FirstOrDefault(x => x.Name == Setup.ApeChieftainRole);

            //Role and permission check
            if (user.Roles.Contains(apeChieftainRole) || user.GuildPermissions.Administrator)
            {
                IMessage message = await emoji.Channel.GetMessageAsync(emoji.MessageId);

                SocketGuildUser otherUser          = message.Author as SocketGuildUser;
                IRole           houseOfGorillaRole = (otherUser as IGuildUser).Guild.Roles.FirstOrDefault(x => x.Name == Setup.HouseOfGorillaRole);
                IRole           houseOfMonkeyRole  = (otherUser as IGuildUser).Guild.Roles.FirstOrDefault(x => x.Name == Setup.HouseOfMonkeyRole);
                IRole           houseOfBaboonRole  = (otherUser as IGuildUser).Guild.Roles.FirstOrDefault(x => x.Name == Setup.HouseOfBaboonRole);
                bool            inHouseOfGorilla   = false;
                bool            inHouseOfMonkey    = false;
                bool            inHouseOfBaboon    = false;

                //Loaded data
                BinaryHouseNormal entry = new BinaryHouseNormal(0, 0, 0);
                //Load
                HouseNormal.Load(Setup.HousePath, ref entry);
                //Modify
                if (otherUser.Roles.Contains(houseOfGorillaRole))
                {
                    entry.GorillaPoints += amount;
                    inHouseOfGorilla     = true;
                }
                if (otherUser.Roles.Contains(houseOfMonkeyRole))
                {
                    entry.MonkeyPoints += amount;
                    inHouseOfMonkey     = true;
                }
                if (otherUser.Roles.Contains(houseOfBaboonRole))
                {
                    entry.BaboonPoints += amount;
                    inHouseOfBaboon     = true;
                }
                //Save
                HouseNormal.Save(Setup.HousePath, entry);

                if (inHouseOfGorilla || inHouseOfMonkey || inHouseOfBaboon)
                {
                    if (inHouseOfGorilla)
                    {
                        await AnnounceGainLoseToHouse(emoji, message, Setup.GorillaWebhookClient, true, amount, entry.GorillaPoints);
                    }
                    if (inHouseOfMonkey)
                    {
                        await AnnounceGainLoseToHouse(emoji, message, Setup.MonkeyWebhookClient, true, amount, entry.MonkeyPoints);
                    }
                    if (inHouseOfBaboon)
                    {
                        await AnnounceGainLoseToHouse(emoji, message, Setup.BaboonWebhookClient, true, amount, entry.BaboonPoints);
                    }
                }
                else
                {
                    EmbedBuilder eb = new EmbedBuilder();
                    eb.Title = "⚠️ **User is not in a house!**";
                    eb.WithColor(Color.Gold);
                    await emoji.Channel.SendMessageAsync("", false, eb.Build());
                }
                await(message as IUserMessage).RemoveAllReactionsAsync();
                await(message as IUserMessage).AddReactionAsync(new Emoji(Setup.GreenCheckEmoji));
            }
        }
Пример #4
0
        public async Task HouseDown(SocketUser mentionedUser, int amount)
        {
            //Roles with access
            List <string> roles = new List <string>();

            roles.Add(Setup.ApeChieftainRole);

            if (await Tools.RolesCheck(Context, roles, true, roles[0]))
            {
                SocketGuildUser otherUser          = mentionedUser as SocketGuildUser;
                IRole           houseOfGorillaRole = Context.Guild.Roles.FirstOrDefault(x => x.Name == Setup.HouseOfGorillaRole);
                IRole           houseOfMonkeyRole  = Context.Guild.Roles.FirstOrDefault(x => x.Name == Setup.HouseOfMonkeyRole);
                IRole           houseOfBaboonRole  = Context.Guild.Roles.FirstOrDefault(x => x.Name == Setup.HouseOfBaboonRole);
                bool            inHouseOfGorilla   = false;
                bool            inHouseOfMonkey    = false;
                bool            inHouseOfBaboon    = false;

                //Loaded data
                BinaryHouseNormal entry = new BinaryHouseNormal(0, 0, 0);
                //Load
                HouseNormal.Load(Setup.HousePath, ref entry);
                //Modify
                if (otherUser.Roles.Contains(houseOfGorillaRole))
                {
                    entry.GorillaPoints -= amount;
                    inHouseOfGorilla     = true;
                }
                if (otherUser.Roles.Contains(houseOfMonkeyRole))
                {
                    entry.MonkeyPoints -= amount;
                    inHouseOfMonkey     = true;
                }
                if (otherUser.Roles.Contains(houseOfBaboonRole))
                {
                    entry.BaboonPoints -= amount;
                    inHouseOfBaboon     = true;
                }
                //Save
                HouseNormal.Save(Setup.HousePath, entry);

                if (inHouseOfGorilla || inHouseOfMonkey || inHouseOfBaboon)
                {
                    if (inHouseOfGorilla)
                    {
                        await AnnounceGainLoseToHouse(Context, Setup.GorillaWebhookClient, false, amount, entry.GorillaPoints);
                    }
                    if (inHouseOfMonkey)
                    {
                        await AnnounceGainLoseToHouse(Context, Setup.MonkeyWebhookClient, false, amount, entry.MonkeyPoints);
                    }
                    if (inHouseOfBaboon)
                    {
                        await AnnounceGainLoseToHouse(Context, Setup.BaboonWebhookClient, false, amount, entry.BaboonPoints);
                    }
                }
                else
                {
                    EmbedBuilder eb = new EmbedBuilder();
                    eb.Title = "⚠️ **User is not in a house!**";
                    eb.WithColor(Color.Gold);
                    await Context.Channel.SendMessageAsync("", false, eb.Build());
                }
            }
            await Context.Message.DeleteAsync();
        }