示例#1
0
            public async Task setPlayerRank(Rank rank, int level = 0)
            {
                if (Context.Message.Channel is SocketGuildChannel guildChannel)
                {
                    if (level != 0 && rank == Rank.GrandChampion)
                    {
                        await Context.Message.Channel.SendMessageAsync("invalid operation");

                        return;
                    }
                    if (level > 3 || level < 1)
                    {
                        await Context.Message.Channel.SendMessageAsync("invalid rank level");

                        return;
                    }
                    Type         enumType   = typeof(Rank);
                    MemberInfo[] memInfo    = enumType.GetMember(rank.ToString());
                    Object[]     attributes = memInfo[0].GetCustomAttributes(typeof(RankAttribute), false);
                    Color        color      = ((RankAttribute)attributes[0]).color;

                    RoleManagerService.CreateOrAddRole(guildChannel.Guild, rank != Rank.GrandChampion ? $"{rank} {level}" : rank.ToString(), Context.Message.Author.Id, Enum.GetNames(typeof(Rank)), color);
                }
                else
                {
                    await Context.Message.Channel.SendMessageAsync("This is a server command only.");
                }
            }
        public async Task AddRoleAsync_Failed_ReturnsFailedResult()
        {
            var sut    = new RoleManagerService(TestRoleManager.GetFailedManager());
            var result = await sut.AddRoleAsync(string.Empty);

            result.Succeeded.Should().BeFalse();
        }
        public async Task AddRoleAsync_Successful_ReturnsSuccessResult()
        {
            var sut    = new RoleManagerService(TestRoleManager.GetSuccessfulManager());
            var result = await sut.AddRoleAsync(string.Empty);

            result.Succeeded.Should().BeTrue();
        }
示例#4
0
            public async Task AddRankRole(int index, ulong roleId)
            {
                if (Context.Message.Channel is SocketGuildChannel guildChannel)
                {
                    //get user from guild
                    SocketGuildUser user = guildChannel.Guild.Users.ToList().Find(u => u.Id == Context.Message.Author.Id);
                    //check guild priviliges
                    if (!AdminModule.IsAuthorized(user))
                    {
                        await Context.Message.Channel.SendMessageAsync("You have no permission for this command.");

                        return;
                    }
                    ulong                   guildId = guildChannel.Guild.Id;
                    SocketGuild             guild   = guildChannel.Guild;
                    Dictionary <int, ulong> guildRankRoleCollection = new Dictionary <int, ulong>();
                    guildRankRoleCollection = RoleManagerService.RankRoleCollection[guildId];
                    if (index > 500)
                    {
                        await Context.Message.Channel.SendMessageAsync("Desired level is too high.");

                        return;
                    }
                    if (guild.Roles.ToList().Find(r => r.Id == roleId) == null)
                    {
                        await Context.Message.Channel.SendMessageAsync("There is no role with this id on this guild.");

                        return;
                    }
                    if (guildRankRoleCollection.Count >= 20)
                    {
                        await Context.Message.Channel.SendMessageAsync("You can't add anymore roles.");

                        return;
                    }
                    if (guildRankRoleCollection.Values.ToList().Contains(roleId))
                    {
                        await Context.Message.Channel.SendMessageAsync("You have already added this role.");

                        return;
                    }
                    if (!guildRankRoleCollection.ContainsKey(index))
                    {
                        guildRankRoleCollection.Add(index, roleId);
                    }
                    guildRankRoleCollection[index] = roleId;
                    RoleManagerService.RankRoleCollection[guildId] = guildRankRoleCollection;
                    RoleManagerService.SaveRankRoleCollection();
                    await Context.Message.Channel.SendMessageAsync($"{guild.Roles.ToList().Find(r => r.Id == roleId).Name} was added with Level {index}.");
                }
                else
                {
                    await Context.Message.Channel.SendMessageAsync("You can only perfom this command on a server.");
                }
            }
示例#5
0
        private async Task Client_Ready()
        {
            AddonLoader.Load(Client);
            Assembly[]  assemblies     = AppDomain.CurrentDomain.GetAssemblies();
            List <Type> commandClasses = new List <Type>();

            foreach (Assembly assembly in assemblies)
            {
                commandClasses.AddRange(assembly.GetTypes().Where(t => t.IsSubclassOf(typeof(ModuleBase)) && !t.IsAbstract).ToList());
            }

            checkNewUserEntries();
            StatusNotifierService.InitializeService(Me);
            MusicCommands.Initialize(Client);
            RoleManagerService.InitializeHandler(Client, BotConfiguration);
            ApiRequestService.Initialize(BotConfiguration);
            UserManagerService.InitializeHandler(Client);
            await CommandHandlerService.InitializeHandler(Client, BotConfiguration, commandClasses, prefixDictionary, !CredentialManager.OptionalSettings.Contains("CleverApi"));

            CacheService.InitializeHandler();
            VoiceRewardService.InitializeHandler(Client, BotConfiguration, !CredentialManager.OptionalSettings.Contains("CleverApi"));
            switch (startValue)
            {
            case 0:
                //shutdown
                break;

            case 1:
                //restarting
                await Me.SendMessageAsync("I have restored and restarted successfully.");

                break;

            case 2:
                //updating
                //check if an update is nessasarry
                await Me.SendMessageAsync("I at all the new features and restarted successfully.");

                break;

            default:
                break;
            }
            if (!CredentialManager.OptionalSettings.Contains("WeatherApiKey"))
            {
                if (!CredentialManager.OptionalSettings.Contains("WeatherPlace"))
                {
                    MoodDictionary.InitializeMoodDictionary(Client, BotConfiguration);
                    await MoodHandlerService.InitializeHandler(Client, BotConfiguration);
                }
                WeatherSubscriptionService.InitializeWeatherSub(Client, BotConfiguration);
            }
        }
示例#6
0
            public async Task RemoveRankRole(int index)
            {
                if (Context.Message.Channel is SocketGuildChannel guildChannel)
                {
                    //check if user has admin priviliges
                    if (AdminModule.IsAuthorized(GeneralModule.GetGuildUserFromGuild(Context.Message.Author as SocketUser, guildChannel.Guild)))
                    {
                        await Context.Message.Channel.SendMessageAsync("You cant do this.");

                        return;
                    }
                    ulong                   guildId = guildChannel.Guild.Id;
                    SocketGuild             guild   = guildChannel.Guild;
                    Dictionary <int, ulong> guildRankRoleCollection = RoleManagerService.RankRoleCollection[guildId];
                    if (guildRankRoleCollection == null)
                    {
                        await Context.Message.Channel.SendMessageAsync("There are no roles to remove.");

                        return;
                    }
                    //if (guild.Roles.ToList().Find(r => r.Id == roleId) == null)
                    //{
                    //    await Context.Message.Channel.SendMessageAsync("This role dont exist on this server.");
                    //    return;
                    //}
                    //if (guildRankRoleCollection.Values.ToList().Contains(roleId))
                    //{
                    //    await Context.Message.Channel.SendMessageAsync("You cant remove this role, because it was never added.");
                    //    return;
                    //}
                    if (!guildRankRoleCollection.ContainsKey(index))
                    {
                        await Context.Message.Channel.SendMessageAsync("The current index is not in your role collection.");

                        return;
                    }
                    guildRankRoleCollection.Remove(index);
                    RoleManagerService.SaveRankRoleCollection();
                    await Context.Message.Channel.SendMessageAsync("Role successfully removed.");
                }
                else
                {
                    await Context.Message.Channel.SendMessageAsync("This is a server command only.");
                }
            }
 public RoleController(UserManagerService userManager, SignManagerService signInManager, RoleManagerService roleManager)
 {
     UserManager   = userManager;
     SignInManager = signInManager;
     RoleManager   = roleManager;
 }
示例#8
0
        public static async Task Initialize(IServiceProvider serviceProvider)
        {
            byte   count    = 0;
            string userPASS = "******";

            var context     = serviceProvider.GetRequiredService <ApplicationDbContext>();
            var userManger  = serviceProvider.GetRequiredService <UserManager <ApplicationUser> >();
            var roleManager = serviceProvider.GetRequiredService <RoleManager <IdentityRole> >();


            var userMangerService = new UserManagerService(userManger);
            var roleManagerSerice = new RoleManagerService(roleManager);

            //var conetextIfExist =  context.Database.EnsureCreated();
            // var context = ApplicationDbContext.Create();


            if (!context.Roles.Any())
            {
                foreach (var role in roles)
                {
                    await roleManagerSerice.CreateRoleAsync(new IdentityRole()
                    {
                        Name = role
                    });
                }
            }

            if (!context.Users.Any())
            {
                var userList = new List <ApplicationUser>()
                {
                    new ApplicationUser()
                    {
                        FirstName   = "Bilal",
                        LastName    = "Aslam",
                        UserName    = "******",
                        Email       = "*****@*****.**",
                        PhoneNumber = "03464131733"
                    },
                    new ApplicationUser()
                    {
                        FirstName   = "Abdul Rehman",
                        LastName    = "Ahsan",
                        UserName    = "******",
                        Email       = "*****@*****.**",
                        PhoneNumber = "03464131733"
                    },
                    new ApplicationUser()
                    {
                        FirstName   = "Waleed",
                        LastName    = "Ahsan",
                        UserName    = "******",
                        Email       = "*****@*****.**",
                        PhoneNumber = "03464131733"
                    }
                };

                foreach (var user in userList)
                {
                    await userMangerService.CreateUserAsync(user, userPASS);

                    await userMangerService.AssignRoleAsync(user.Id, roles[count++]);
                }
            }
        }
示例#9
0
        private async Task Client_Ready()
        {
            IServiceProvider services = new ServiceCollection()
                                        .AddSingleton(Client)
                                        .AddSingleton <CleverbotApiHandler>()
                                        .AddSingleton <ColornamesApiHandler>()
                                        .AddSingleton <KonachanApiHandler>()
                                        .AddSingleton <WeatherApiHandler>()
                                        .AddSingleton <WikipediaApiHandler>()
                                        .AddSingleton(CredentialManager)
                                        .BuildServiceProvider();

            AddonLoader.Load(Client);
            Assembly[]  assemblies     = AppDomain.CurrentDomain.GetAssemblies();
            List <Type> commandClasses = new List <Type>();

            foreach (Assembly assembly in assemblies)
            {
                commandClasses.AddRange(assembly.GetTypes().Where(t => t.IsSubclassOf(typeof(ModuleBase)) && !t.IsAbstract).ToList());
            }
            VoiceRewardService.InitializeHandler(Client, BotConfiguration, !CredentialManager.OptionalSettings.Contains("CleverApi"));
            checkNewUserEntries();
            StatusNotifierService.InitializeService(Me);
            MusicCommands.Initialize(Client);
            RoleManagerService.InitializeHandler(Client, BotConfiguration);
            UserManagerService.InitializeHandler(Client, fileLogger);
            await CommandHandlerService.InitializeHandler(Client, BotConfiguration, commandClasses, prefixDictionary, !CredentialManager.OptionalSettings.Contains("CleverApi"), fileLogger, services);

            CacheService.InitializeHandler();
            switch (startValue)
            {
            case 0:
                //shutdown
                break;

            case 1:
                //restarting
                await Me.SendMessageAsync("I have restored and restarted successfully.");

                break;

            case 2:
                //updating
                //check if an update is nessasarry
                await Me.SendMessageAsync("I at all the new features and restarted successfully.");

                break;

            default:
                break;
            }
            if (!CredentialManager.OptionalSettings.Contains("WeatherApiKey"))
            {
                if (!CredentialManager.OptionalSettings.Contains("WeatherPlace"))
                {
                    MoodDictionary.InitializeMoodDictionary(Client, BotConfiguration);
                    await MoodHandlerService.InitializeHandler(Client, BotConfiguration, services.GetRequiredService <WeatherApiHandler>(), fileLogger);
                }
                WeatherSubscriptionService.InitializeWeatherSub(Client, BotConfiguration, services.GetRequiredService <WeatherApiHandler>());
            }
            consoleLogger.Info($"Addons loaded: {AddonLoader.LoadedAddonsCount}");
            consoleLogger.Info($"User loaded: {DatabaseAccess.Instance.Users.Count}");
            consoleLogger.Info($"Registered guilds: {Client.Guilds.Count}");
            consoleLogger.Info($"Bot start up time: {(DateTime.Now - startTime).TotalSeconds} s");
        }
示例#10
0
 public RoleManagerController(RoleManagerService roleManager)
 {
     _roleManager = roleManager;
 }
示例#11
0
 public ValuesController(RoleManagerService roleManager, UserManager <ApplicationUser> userManager)
 {
     _roleManager = roleManager;
     _userManager = userManager;
 }