Пример #1
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);
        }