Пример #1
0
 public string ToTranslate(BotTranslationString str, GuildLanguage lang, params object[] list)
 {
     try
     {
         return(Translate.GetBotTranslation(str, lang, list));
     }
     catch (Exception e)
     {
         throw e;
     }
 }
Пример #2
0
 public string GetAssetRegistryTranslation(string key, GuildLanguage guildCulture, params object[] arguments)
 {
     return(GetAssetRegistryTranslation(key, guildCulture.ToString(), arguments));
 }
Пример #3
0
 public string GetBotTranslation(string key, GuildLanguage guildCulture, params object[] arguments)
 {
     return(GetBotString(key, new CultureInfo(guildCulture.ToString().ToLower()), arguments));
 }
Пример #4
0
        public bool Enable(SocketGuild guild, GuildLanguage lang)
        {
            if (guild == null || !guild.CurrentUser.GuildPermissions.ManageRoles || !guild.CurrentUser.GuildPermissions.ManageNicknames)
            {
                return(false);
            }

            var reorder2 = new List <ReorderRoleProperties>();

            {
                var         discordServer = _uow.Db <DiscordServer>().GetById(guild.Id.ToString());
                GuildConfig gConfig       = null;

                if (discordServer == null)
                {
                    gConfig = AddOrGetGuild(guild.Id.ToString(), lang).Value;
                }
                else
                {
                    gConfig = AddOrGetGuildConfig(guild.Id.ToString());
                }

                var list = guild.GetMissingMapRolesAsync(gConfig.Owner.DefaultLanguage, out reorder2).Result;

                if (list == null || list.Count < 4)
                {
                    return(false);
                }

                try
                {
                    foreach (var crole in list)
                    {
                        crole.Value.SetMapRolePermissionsAsync();
                    }
                }
                catch (AggregateException e)
                {
                    try
                    {
                        guild.Owner.GetOrCreateDMChannelAsync(Core.Utils.RequestOption)
                        .ContinueWith((p1) =>
                        {
                            p1.Result.SendMessageAsync(e.Message)
                            .ContinueWith((p2) =>
                            {
                                p1.Result.CloseAsync(Core.Utils.RequestOption).Wait();
                            });
                        });
                    }
                    catch (Exception)
                    {
                    }
                }
                catch (Exception)
                {
                }
                try
                {
                    if (reorder2.Count >= 4)
                    {
                        guild.ReorderRolesAsync(reorder2, Core.Utils.RequestOption).Wait();
                    }
                }
                catch (Exception)
                {
                };
            }
            return(true);
        }
Пример #5
0
        public KeyValuePair <DiscordServer, GuildConfig> AddOrGetGuild(string guildId, GuildLanguage lang = GuildLanguage.EN)
        {
            var svr = _uow.Db <DiscordServer>().GetById(guildId);

            if (svr == null)
            {
                svr = new DiscordServer {
                    Id = guildId, Language = lang
                };
                _uow.Db <DiscordServer>().Add(svr);
                _uow.Commit();
            }
            var gConfig = AddOrGetGuildConfig(guildId);

            return(new KeyValuePair <DiscordServer, GuildConfig>(svr, gConfig));
        }
Пример #6
0
        public static Task <Dictionary <MapRoles, IRole> > GetUserRolesAsync(this IGuildUser user, GuildLanguage lang)
        {
            if (user == null)
            {
                return(Task.FromResult(new Dictionary <MapRoles, IRole>()));
            }
            return(Task.Run(() =>
            {
                var curGuild = user.Guild;
                var Translate = DIManager.Services.GetRequiredService <IJsonStringLocalizer>();
                var guildRoles = curGuild.Roles.Where(p => p.Name == Translate.GetBotTranslation(BotTranslationString.Stonewood, lang) ||
                                                      p.Name == Translate.GetBotTranslation(BotTranslationString.Plankerton, lang) ||
                                                      p.Name == Translate.GetBotTranslation(BotTranslationString.CannyValley, lang) ||
                                                      p.Name == Translate.GetBotTranslation(BotTranslationString.TwinePeaks, lang) ||
                                                      p.Name == Translate.GetBotTranslation(BotTranslationString.noname, lang));

                var rl = guildRoles.Where(f => user.RoleIds.Contains(f.Id));

                var scrl = new Dictionary <MapRoles, IRole>();
                foreach (var r in rl)
                {
                    if (r.Name == Translate.GetBotTranslation(BotTranslationString.Stonewood, lang))
                    {
                        scrl.Add(MapRoles.Stonewood, r);
                    }
                    else if (r.Name == Translate.GetBotTranslation(BotTranslationString.Plankerton, lang))
                    {
                        scrl.Add(MapRoles.Plankerton, r);
                    }
                    else if (r.Name == Translate.GetBotTranslation(BotTranslationString.CannyValley, lang))
                    {
                        scrl.Add(MapRoles.CannyValley, r);
                    }
                    else if (r.Name == Translate.GetBotTranslation(BotTranslationString.TwinePeaks, lang))
                    {
                        scrl.Add(MapRoles.TwinePeaks, r);
                    }
                    else if (r.Name == Translate.GetBotTranslation(BotTranslationString.noname, lang))
                    {
                        scrl.Add(MapRoles.noname, r);
                    }
                }
                return scrl;
            }));
        }
Пример #7
0
        public static Embed ToWebhookEmbed(this IMissionX mission, GuildLanguage language = GuildLanguage.EN)
        {
            int          xy    = 0;
            EmbedBuilder embed = new EmbedBuilder();

            try
            {
                if (mission.MissionNameInfo.Name == "Launch the Rocket")
                {
                    return(null);
                }
                string GroupMission = $"";
                if (mission.IsGroupMission)
                {
                    GroupMission = $"{SurvivorStaticData.Get4xGroupMissionImage()}";
                }

                bool firstAlertSet = false;

                var           time          = mission.availableUntil.ToStringHMS();
                var           Translate     = DIManager.Services.GetRequiredService <IJsonStringLocalizer>();
                string        availableTime = Translate.GetBotTranslation(BotTranslationString.MA_ExpreIn, language, time);
                List <string> mapRewards    = new List <string>();
                List <string> alertRewards  = new List <string>();
                string        alertNameStr  = "";
                foreach (var item in mission.Items)
                {
                    if (item.AlertReward && firstAlertSet == false)
                    {
                        firstAlertSet = true;

                        alertNameStr = mission.MissionCategory.ToDescriptionString();
                    }
                    string amount = "";
                    if (item.AlertReward && item.quantity > 1)
                    {
                        amount = $"(**x{item.quantity:#,##0.##}**)";
                    }
                    else
                    {
                        if (item.AlertReward && item.quantity == 4)
                        {
                            amount = $"(**x4**)";
                        }
                        else if (item.AlertReward && item.quantity != 1)
                        {
                            amount = $"(**x{item.quantity}**)";
                        }
                    }
                    var itmInfo = item.GetRealItemName(false, language.ToString());
                    if (item.AlertReward == false)
                    {
                        mapRewards.Add($"<:{itmInfo.Key}:{itmInfo.Key}> *{itmInfo.Value}* {amount}");
                    }
                    else
                    {
                        alertRewards.Add($"<:{itmInfo.Key}:{itmInfo.Key}> *{itmInfo.Value}* {amount}");
                    }
                }
                string mapLevel = mission.MissionLevel.ToString();
                embed.Title       = $"{mapLevel}:zap: {mission.MissionNameInfo.Name} {GroupMission} <:{mission.MissionNameInfo.EmojiId}:{mission.MissionNameInfo.EmojiId}>";
                embed.Description = $"**{Translate.GetBotTranslation(mission.WorldName.ToString().Replace("_", ""), language)}**";
                embed.WithFooter($"{availableTime}");
                embed.AddField(Translate.GetBotTranslation(BotTranslationString.MA_Rewards, language), string.Join("\n", mapRewards.ToArray()), true);
                embed.AddField($"**{alertNameStr}**", string.Join("\n", alertRewards.ToArray()), true);
                string positive_mutations = "";
                string negative_mutations = "";
                int    p = 0, n = 0;
                foreach (var mutation in mission.Modifiers)
                {
                    string mId = Fortnite.Static.Utils.GetImage(mutation.AssetId);
                    if (mutation.IsPositiveMutation.Value)
                    {
                        n++;
                        positive_mutations += $"<:{mId}:{mId}> ";
                        if (n % 5 == 0)
                        {
                            positive_mutations += "\n";
                        }
                    }
                    else
                    {
                        p++;
                        negative_mutations += $"<:{mId}:{mId}> ";
                        if (p % 5 == 0)
                        {
                            negative_mutations += "\n";
                        }
                    }
                }

                if (positive_mutations.Length != 0 && negative_mutations.Length != 0)
                {
                    embed.AddField(Translate.GetBotTranslation(BotTranslationString.MA_NegativeMutation, language), negative_mutations, false);
                    embed.AddField(Translate.GetBotTranslation(BotTranslationString.MA_PositiveMutation, language), positive_mutations, true);
                }
                else if (negative_mutations.Length == 0 || positive_mutations.Length != 0)
                {
                    embed.AddField(Translate.GetBotTranslation(BotTranslationString.MA_PositiveMutation, language), positive_mutations, false);
                }
                else if (negative_mutations.Length != 0 || positive_mutations.Length == 0)
                {
                    embed.AddField(Translate.GetBotTranslation(BotTranslationString.MA_NegativeMutation, language), negative_mutations, false);
                }
                if (mission.AnyEpic())
                {
                    embed.Color = new Color(187, 143, 206);
                }

                if (mission.AnyLegendary())
                {
                    embed.Color = new Color(248, 196, 113);
                }

                if (mission.HasVBuck())
                {
                    embed.Color = new Color(133, 193, 233);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                Console.WriteLine("-------------------------------------------");

                Console.WriteLine(JsonConvert.SerializeObject(mission));

                Console.WriteLine("-------------------------------------------");
            }
            return(embed.Build());
        }
Пример #8
0
        public static Task <Dictionary <MapRoles, IRole> > GetMissingMapRolesAsync(this IGuild guild, GuildLanguage lang, out List <ReorderRoleProperties> reorder)
        {
            reorder = new List <ReorderRoleProperties>();
            try
            {
                var list = reorder;
                var t    = Task.Run(() =>
                {
                    var curUser = guild.GetCurrentUserAsync().Result;

                    var userRoles = guild.Roles.Where(f => curUser.RoleIds.Contains(f.Id));

                    var positionOfMinManagedRol = userRoles
                                                  .Where(s => s.Permissions.ManageRoles)
                                                  .OrderByDescending(s => s.Position)
                                                  .FirstOrDefault();

                    if (positionOfMinManagedRol == null)
                    {
                        return(null);
                    }
                    List <Task> taskList = new List <Task>();
                    Dictionary <MapRoles, IRole> roles = new Dictionary <MapRoles, IRole>();

                    var dicRoles  = FTNPower.Core.Utils.GetMapRolesAsync(guild, lang).Result;
                    var Translate = DIManager.Services.GetRequiredService <IJsonStringLocalizer>();
                    var lmap4     = Translate.GetBotTranslation(BotTranslationString.TwinePeaks, lang);
                    var lmap3     = Translate.GetBotTranslation(BotTranslationString.CannyValley, lang);
                    var lmap2     = Translate.GetBotTranslation(BotTranslationString.Plankerton, lang);
                    var lmap1     = Translate.GetBotTranslation(BotTranslationString.Stonewood, lang);
                    var lmap0     = Translate.GetBotTranslation(BotTranslationString.noname, lang);

                    var q1 = dicRoles.FirstOrDefault(s =>
                                                     s.Value.Name == lmap4);
                    if (q1.Value == null)
                    {
                        taskList.Add(guild
                                     .CreateRoleAsync(lmap4, GuildPermissions.None, new Color(0xff, 0xa3, 0x00), true,
                                                      Core.Utils.RequestOption)
                                     .ContinueWith(
                                         (p) =>
                        {
                            try
                            {
                                roles.Add(MapRoles.TwinePeaks, p.Result);
                                list.Add(new ReorderRoleProperties(p.Result.Id, positionOfMinManagedRol.Position));
                            }
                            catch
                            {
                            }
                        }));
                    }
                    else
                    {
                        roles.Add(MapRoles.TwinePeaks, q1.Value);
                        list.Add(new ReorderRoleProperties(q1.Value.Id, positionOfMinManagedRol.Position));
                    }

                    var q2 = dicRoles.FirstOrDefault(s => s.Value.Name == lmap3);
                    if (q2.Value == null)
                    {
                        taskList.Add(guild
                                     .CreateRoleAsync(lmap3, GuildPermissions.None, new Color(0xa8, 0x58, 0xf3), true,
                                                      Core.Utils.RequestOption)
                                     .ContinueWith(
                                         (o) =>
                        {
                            try
                            {
                                roles.Add(MapRoles.CannyValley, o.Result);
                                list.Add(new ReorderRoleProperties(o.Result.Id, positionOfMinManagedRol.Position));
                            }
                            catch
                            {
                            }
                        }));
                    }
                    else
                    {
                        roles.Add(MapRoles.CannyValley, q2.Value);
                        list.Add(new ReorderRoleProperties(q2.Value.Id, positionOfMinManagedRol.Position));
                    }

                    var q3 = dicRoles.FirstOrDefault(s =>
                                                     s.Value.Name == lmap2);
                    if (q3.Value == null)
                    {
                        taskList.Add(guild
                                     .CreateRoleAsync(lmap2, GuildPermissions.None, new Color(0x06, 0x6f, 0xf5), true,
                                                      Core.Utils.RequestOption)
                                     .ContinueWith(
                                         (o) =>
                        {
                            try
                            {
                                roles.Add(MapRoles.Plankerton, o.Result);
                                list.Add(new ReorderRoleProperties(o.Result.Id, positionOfMinManagedRol.Position));
                            }
                            catch
                            {
                            }
                        }));
                    }
                    else
                    {
                        roles.Add(MapRoles.Plankerton, q3.Value);
                        list.Add(new ReorderRoleProperties(q3.Value.Id, positionOfMinManagedRol.Position));
                    }

                    var q4 = dicRoles.FirstOrDefault(s =>
                                                     s.Value.Name == lmap1);
                    if (q4.Value == null)
                    {
                        taskList.Add(guild
                                     .CreateRoleAsync(lmap1, GuildPermissions.None, new Color(0x4f, 0xe9, 0x0a), true,
                                                      Core.Utils.RequestOption)
                                     .ContinueWith(
                                         (o) =>
                        {
                            try
                            {
                                roles.Add(MapRoles.Stonewood, o.Result);
                                list.Add(new ReorderRoleProperties(o.Result.Id, positionOfMinManagedRol.Position));
                            }
                            catch        // (Exception e)
                            {
                            }
                        }));
                    }
                    else
                    {
                        roles.Add(MapRoles.Stonewood, q4.Value);
                        list.Add(new ReorderRoleProperties(q4.Value.Id, positionOfMinManagedRol.Position));
                    }

                    var q5 = dicRoles.FirstOrDefault(s =>
                                                     s.Value.Name == lmap0);
                    if (q5.Value == null)
                    {
                        taskList.Add(guild
                                     .CreateRoleAsync(lmap0, GuildPermissions.None, new Color(0, 0, 0), false, Core.Utils.RequestOption)
                                     .ContinueWith((o) =>
                        {
                            try
                            {
                                roles.Add(MapRoles.noname, o.Result);
                                list.Add(new ReorderRoleProperties(o.Result.Id, positionOfMinManagedRol.Position));
                            }
                            catch
                            {
                            }
                        }));
                    }
                    else
                    {
                        roles.Add(MapRoles.noname, q5.Value);
                        list.Add(new ReorderRoleProperties(q5.Value.Id, positionOfMinManagedRol.Position));
                    }

                    if (taskList.Count > 0)
                    {
                        Task.WaitAll(taskList.ToArray());
                    }
                    return(roles);
                });
                t.Wait();
                reorder = list;
                return(t);
            }
            catch
            {
                return(null);
            }
        }
Пример #9
0
        public static Task <Dictionary <MapRoles, IRole> > GetMapRolesAsync(this IGuild guild, GuildLanguage lang)
        {
            return(Task.Run(() =>
            {
                var Translate = DIManager.Services.GetRequiredService <IJsonStringLocalizer>();
                var rl = guild.Roles.Where(p => p.Name == Translate.GetBotTranslation(BotTranslationString.Stonewood, lang) ||
                                           p.Name == Translate.GetBotTranslation(BotTranslationString.Plankerton, lang) ||
                                           p.Name == Translate.GetBotTranslation(BotTranslationString.CannyValley, lang) ||
                                           p.Name == Translate.GetBotTranslation(BotTranslationString.TwinePeaks, lang) ||
                                           p.Name == Translate.GetBotTranslation(BotTranslationString.noname, lang))
                         .OrderBy(p => p.Name);

                var scrl = new Dictionary <MapRoles, IRole>();
                foreach (var r in rl)
                {
                    if (r.Name == Translate.GetBotTranslation(BotTranslationString.Stonewood, lang))
                    {
                        if (!scrl.ContainsKey(MapRoles.Stonewood))
                        {
                            scrl.Add(MapRoles.Stonewood, r);
                        }
                    }
                    else if (r.Name == Translate.GetBotTranslation(BotTranslationString.Plankerton, lang))
                    {
                        if (!scrl.ContainsKey(MapRoles.Plankerton))
                        {
                            scrl.Add(MapRoles.Plankerton, r);
                        }
                    }
                    else if (r.Name == Translate.GetBotTranslation(BotTranslationString.CannyValley, lang))
                    {
                        if (!scrl.ContainsKey(MapRoles.CannyValley))
                        {
                            scrl.Add(MapRoles.CannyValley, r);
                        }
                    }
                    else if (r.Name == Translate.GetBotTranslation(BotTranslationString.TwinePeaks, lang))
                    {
                        if (!scrl.ContainsKey(MapRoles.TwinePeaks))
                        {
                            scrl.Add(MapRoles.TwinePeaks, r);
                        }
                    }
                    else if (r.Name == Translate.GetBotTranslation(BotTranslationString.noname, lang))
                    {
                        if (!scrl.ContainsKey(MapRoles.noname))
                        {
                            scrl.Add(MapRoles.noname, r);
                        }
                    }
                }
                return scrl;
            }));
        }