Пример #1
0
        public void SetBasePriority()
        {
            var table = new PriorityTable();

            table.SetBasePriority(6);

            Console.WriteLine("Priority table with base priority = 6");
            for (int i = 0; i < 168; i++)
            {
                Console.WriteLine("Y = {0} ; Priority = {1}", i, table.GetPriorityAt(i));
            }

            table.GetPriorityAt(0).Should().Be(4);
            table.GetPriorityAt(5).Should().Be(4);
            table.GetPriorityAt(6).Should().Be(5);
            table.GetPriorityAt(22).Should().Be(5);
            table.GetPriorityAt(23).Should().Be(6);
            table.GetPriorityAt(38).Should().Be(6);
            table.GetPriorityAt(39).Should().Be(7);
            table.GetPriorityAt(54).Should().Be(7);
            table.GetPriorityAt(55).Should().Be(8);
            table.GetPriorityAt(70).Should().Be(8);
            table.GetPriorityAt(71).Should().Be(9);
            table.GetPriorityAt(86).Should().Be(9);
            table.GetPriorityAt(87).Should().Be(10);
            table.GetPriorityAt(103).Should().Be(10);
            table.GetPriorityAt(104).Should().Be(11);
            table.GetPriorityAt(119).Should().Be(11);
            table.GetPriorityAt(120).Should().Be(12);
            table.GetPriorityAt(135).Should().Be(12);
            table.GetPriorityAt(136).Should().Be(13);
            table.GetPriorityAt(151).Should().Be(13);
            table.GetPriorityAt(152).Should().Be(14);
            table.GetPriorityAt(167).Should().Be(14);
        }
Пример #2
0
        public void CreateDefault()
        {
            var table = new PriorityTable();

            Console.WriteLine("Default priority table");
            for (int i = 0; i < 168; i++)
            {
                Console.WriteLine("Y = {0} ; Priority = {1}", i, table.GetPriorityAt(i));
            }

            table.GetPriorityAt(0).Should().Be(4);
            table.GetPriorityAt(47).Should().Be(4);
            table.GetPriorityAt(48).Should().Be(5);
            table.GetPriorityAt(59).Should().Be(5);
            table.GetPriorityAt(60).Should().Be(6);
            table.GetPriorityAt(71).Should().Be(6);
            table.GetPriorityAt(72).Should().Be(7);
            table.GetPriorityAt(83).Should().Be(7);
            table.GetPriorityAt(84).Should().Be(8);
            table.GetPriorityAt(95).Should().Be(8);
            table.GetPriorityAt(96).Should().Be(9);
            table.GetPriorityAt(107).Should().Be(9);
            table.GetPriorityAt(108).Should().Be(10);
            table.GetPriorityAt(119).Should().Be(10);
            table.GetPriorityAt(120).Should().Be(11);
            table.GetPriorityAt(131).Should().Be(11);
            table.GetPriorityAt(132).Should().Be(12);
            table.GetPriorityAt(143).Should().Be(12);
            table.GetPriorityAt(144).Should().Be(13);
            table.GetPriorityAt(155).Should().Be(13);
            table.GetPriorityAt(156).Should().Be(14);
            table.GetPriorityAt(167).Should().Be(14);
        }
Пример #3
0
 public static PriorityState GetPriorityState(this PriorityTable pt)
 {
     if (pt.CheckValidity())
     {
         return(pt.State);
     }
     else
     {
         return(PriorityState.Normal);
     }
 }
Пример #4
0
        public static void Initialize()
        {
            BotContext context = DIManager.Services.GetRequiredService <BotContext>();

            context.Database.EnsureCreated();
            BotConfig config = new BotConfig(DIManager.Services.DiscordBotConfigs().ProjectName, DIManager.Services.DiscordBotConfigs().DiscordAppToken);

            if (context.Configs.Find(config.Id) == null)
            {
                context.Configs.Add(config);
            }

            PriorityTable ptable1 = new PriorityTable();//fortnitepower

            ptable1.Id       = $"s{465028350067605504}";
            ptable1.Deadline = DateTimeOffset.UtcNow.AddYears(1);
            if (context.PriorityTables.Find(ptable1.Id) == null)
            {
                context.PriorityTables.Add(ptable1);
            }

            PriorityTable ptable2 = new PriorityTable();//fırtına kalkanı türkiye

            ptable2.Id       = $"s{450233662739578880}";
            ptable2.Deadline = DateTimeOffset.UtcNow.AddYears(1);
            if (context.PriorityTables.Find(ptable2.Id) == null)
            {
                context.PriorityTables.Add(ptable2);
            }

            PriorityTable ptable3 = new PriorityTable();//kesintisiz#9182

            ptable3.Id       = $"u{193749607107395585}";
            ptable3.Deadline = DateTimeOffset.UtcNow.AddYears(1);
            if (context.PriorityTables.Find(ptable3.Id) == null)
            {
                context.PriorityTables.Add(ptable3);
            }
            var         exampleGuildConfig = "{  \n   \"Id\":\"465028350067605504\",  \n   \"Owner\":{  \n      \"DefaultLanguage\":0,  \n      \"AutoRemoveRequest\":false,  \n      \"DefaultGameMode\":1,  \n      \"PVEDecimalState\":false,  \n      \"RestrictedRoleIds\":[  \n           \n      ]  \n   },  \n   \"Admin\":{  \n      \"MissionStates\":{  \n         \"Active\":false,  \n         \"Channels\":[  \n            {  \n               \"MissionType\":0,  \n               \"ChannelId\":\"525161479234781194\",  \n               \"RoleId\":\"\"  \n            }  \n         ]  \n      },  \n      \"LlamaSates\":{  \n         \"Active\":false,  \n         \"ChannelId\":\"568887871910576128\",  \n         \"RoleIdToMention\":\"\"  \n      },  \n      \"BrStoreStates\":{  \n         \"Active\":false,  \n         \"ChannelId\":\"576997364578123787\",  \n         \"RoleIdToMention\":\"\"  \n      },  \n      \"StwStoreStates\":{  \n         \"Active\":false,  \n         \"ChannelId\":\"672260410098843658\",  \n         \"RoleIdToMention\":\"\"  \n      }  \n   },  \n   \"Other\":{  \n        \n   },  \n   \"Event\":{  \n      \"MythicSKStates\":{  \n         \"Active\":true,  \n         \"RoleIdToMythicSK\":\"648882849872871447\"  \n      },  \n      \"EliteFrostnite2019s\":{  \n         \"Active\":true,  \n         \"RoleId\":\"655216469201780751\"  \n      }  \n   }  \n}";
            GuildConfig guildConfig        = JsonConvert.DeserializeObject <GuildConfig>(exampleGuildConfig);

            //guildConfig.Id = "";//guild ID
            //guildConfig.Admin.BrStoreStates.ChannelId = "";//webhook channel id
            //guildConfig.Admin.LlamaSates.ChannelId = "";//webhook channel id
            //guildConfig.Admin.MissionStates.Channels.Add(new ChannelItem() { ChannelId = ""/*webhook channel id*/, MissionType=MissionType.All_TheSame_Channel,/* RoleId="" //mentioned role id,not required*/ });
            //guildConfig.Admin.StwStoreStates.ChannelId = "";//webhook channel id
            //context.GuildConfigs.Add(guildConfig);


            //look at in 'SQL' folder search 'ftnpower_database_example_data.sql'

            context.SaveChanges();
        }
Пример #5
0
        public PriorityTable UpdatePriority(string id, string extendFormat, string customText = null)
        {
            Regex extendRegex = new Regex("(\\d+)M|(\\d+)d|(\\d+)h");
            Regex extendId    = new Regex("(s|u)(\\d+)");
            var   extendMatch = extendRegex.Match(extendFormat);
            var   idMatch     = extendId.Match(id.ToLowerInvariant());

            if (extendMatch.Success && idMatch.Success)
            {
                PriorityTable tbl = _uow.Db <PriorityTable>().GetById(id);
                if (tbl == null)
                {
                    tbl = new PriorityTable
                    {
                        Id       = id,
                        Deadline = DateTimeOffset.UtcNow.AddMilliseconds(-1),
                        Notified = false
                    };
                    tbl = _uow.Db <PriorityTable>().Add(tbl).Entity;
                    _uow.Commit();
                }
                else
                {
                    if (!((tbl.Deadline - DateTimeOffset.UtcNow).TotalSeconds > 0))
                    {
                        tbl.Deadline = DateTimeOffset.UtcNow.AddMilliseconds(-1);
                    }
                }
                if (!string.IsNullOrWhiteSpace(customText))
                {
                    if (customText.Equals("null", StringComparison.InvariantCultureIgnoreCase))
                    {
                        tbl.AdvertOn = false;
                    }
                    else
                    {
                        tbl.AdvertCustomText = customText;
                        tbl.AdvertOn         = true;
                    }
                }
                var months = extendMatch.Groups[1];
                if (months.Success)
                {
                    var m = int.Parse(months.Value);
                    tbl.Deadline = tbl.Deadline.AddMonths(m).AddSeconds(15);
                    if (m > 0)
                    {
                        tbl.Notified = false;
                    }
                }
                var days = extendMatch.Groups[2];
                if (days.Success)
                {
                    var d = int.Parse(days.Value);
                    tbl.Deadline = tbl.Deadline.AddDays(d).AddSeconds(15);
                    if (d > 0)
                    {
                        tbl.Notified = false;
                    }
                }
                var hours = extendMatch.Groups[3];
                if (hours.Success)
                {
                    var h = int.Parse(hours.Value);
                    tbl.Deadline = tbl.Deadline.AddHours(h).AddSeconds(15);
                    if (h > 0)
                    {
                        tbl.Notified = false;
                    }
                }
                _uow.Db <PriorityTable>().Update(tbl);
                _uow.Commit();

                _redis.JsonDelete <List <PriorityTable> >();
                return(tbl);
            }
            else
            {
                return(null);
            }
        }
Пример #6
0
        public Task PriorityUpdate(string id = "", string extendFormat = "", [Remainder] string customText = null)
        {
            return(Task.Run(async() =>
            {
                PriorityTable priority = Context.Repo.Priority.UpdatePriority(id, extendFormat, customText);
                if (priority != null)
                {
                    IGuildUser usr = null;
                    IGuild gld = null;
                    string namefor = "";
                    if (priority.State == PriorityState.User)
                    {
                        usr = Context.DiscordRestApi.GetGuildUserAsync(this.Context.Guild.Id, priority.GetUlongId()).Result;
                        namefor = $"{usr?.Username}#{usr?.Discriminator}";
                    }
                    else if (priority.State == PriorityState.Guild)
                    {
                        gld = Context.DiscordRestApi.GetApi.GetGuildAsync(priority.GetUlongId()).Result;
                        usr = gld?.GetOwnerAsync().Result;
                        namefor = $"{gld?.Name}";
                    }
                    else
                    {
                        throw new Exception("undefined PriorityState for PriorityManager");
                    }
                    if (priority.CheckValidity())
                    {
                        DateTime dtx = new DateTime();
                        dtx = dtx.Add(priority.Remining);
                        EmbedBuilder embed = new EmbedBuilder()
                        {
                            Author = new EmbedAuthorBuilder()
                            {
                                IconUrl = Context.Guild.CurrentUser.GetAvatarUrl(),
                                Name = Context.Guild.CurrentUser.Username
                            },
                            Color = Color.Green,
                            Title = "DISCORD PLAN IS UPDATED",
                        };
                        embed.Description += $"Type: **{priority.State}**\n" +
                                             $"Name: {namefor}\n" +
                                             $"Expires In: **{dtx.Year - 1}**Years **{dtx.Month - 1}**Months **{dtx.Day - 1}**days **{dtx.Hour}**hours\n";
                        embed.Description += "\n\n";
                        string text = $"[id:**{priority.Id}**][**{namefor}**].";
                        Log.Information("Priority: subs state is updated via cmd for {CustomerPriorityId} name with {CustomerName}, value {AddedValue} and Text {CustomText}", priority.Id, namefor, extendFormat, customText);
                        try
                        {
                            var dm = await usr.GetOrCreateDMChannelAsync();
                            var msg = await dm.SendMessageAsync(string.Empty, false, embed.Build(), Core.Utils.RequestOption);
                            await dm.CloseAsync(Core.Utils.RequestOption);
                        }

                        catch (Exception e)

                        {
                            await ReplyEmbedAsync($"{text} but DM was close, **COULDN'T** informed.", "DISCORD PLAN IS UPDATED");
                            return;
                        }
                        await ReplyEmbedAsync(text, "DISCORD PLAN IS UPDATED");
                    }
                    else
                    {
                        await ReplyEmbedAsync($"[id:{priority.Id}][{namefor}]. but was **expired**", "DISCORD PLAN IS UPDATED");
                    }
                }
                else
                {
                    await ReplyEmbedErrorAsync("format is not correct i.e.:\n **u193749607107395585** **1M** **1d** **1h** **Text**/**null(off)**(not required)");
                }
            }));
        }
Пример #7
0
 private int GetOperatorPrioretet(string op)
 {
     return(PriorityTable.FirstOrDefault(x => x.Contains(op))?.Priority ?? -1);
 }
Пример #8
0
 public static bool CheckValidity(this PriorityTable pt)
 {
     return(pt.Remining.TotalSeconds > 0);
 }
Пример #9
0
 public static ulong GetUlongId(this PriorityTable pt)
 {
     return(ulong.Parse(pt.Id.Substring(1)));
 }