Esempio n. 1
0
        public async Task AddOptRole(string optRoleBaseName, string roleToAssignName,
                                     [Remainder] string requiredRoleName = "")
        {
            SocketRole roleToAssign = RoleUtils.GetGuildRole(Context.Guild, roleToAssignName);

            //Check to make sure the role exists first
            if (roleToAssign == null)
            {
                await Context.Channel.SendMessageAsync("You need to input a valid role to give!");

                return;
            }

            //If a required role was specified, check to make sure it exists
            SocketRole requiredRole = null;

            if (!string.IsNullOrWhiteSpace(requiredRoleName))
            {
                requiredRole = RoleUtils.GetGuildRole(Context.Guild, requiredRoleName);
                if (requiredRole == null)
                {
                    await Context.Channel.SendMessageAsync($"Role {requiredRoleName} doesn't exist!");

                    return;
                }
            }

            ServerList server = ServerListsManager.GetServer(Context.Guild);

            //Check to make sure a role give doesn't already exist first
            if (server.GetOptRole(optRoleBaseName) != null)
            {
                await Context.Channel.SendMessageAsync(
                    $"An opt role with the name '{optRoleBaseName}' already exists!");

                return;
            }

            //Create and add our new opt role
            OptRole roleGive = new OptRole
            {
                Name           = optRoleBaseName,
                RoleToGiveId   = roleToAssign.Id,
                RoleRequiredId = 0
            };

            if (requiredRole != null)
            {
                roleGive.RoleRequiredId = requiredRole.Id;
            }

            server.RoleGives.Add(roleGive);
            ServerListsManager.SaveServerList();

            await Context.Channel.SendMessageAsync($"An opt role with the name `{optRoleBaseName}` was created.");
        }
Esempio n. 2
0
        public async Task GiveOptRole([Remainder] string optRoleName = "")
        {
            SocketGuildUser user = (SocketGuildUser)Context.User;

            if (user == null)
            {
                return;
            }

            //Make sure the imputed optRoleName is not empty or null
            if (string.IsNullOrWhiteSpace(optRoleName))
            {
                await Context.Channel.SendMessageAsync("You need to input an opt role name!");

                return;
            }

            //Get the opt role
            OptRole optRole = ServerListsManager.GetServer(Context.Guild).GetOptRole(optRoleName);

            if (optRole == null)             //And make sure it exists!
            {
                await Context.Channel.SendMessageAsync("That opt role doesn't exist!");

                return;
            }

            //If the opt role has a required role, make sure the user has it
            if (optRole.RoleRequiredId != 0)
            {
                //The user doesn't have the required role
                if (!user.UserHaveRole(optRole.RoleRequiredId))
                {
                    await Context.Channel.SendMessageAsync("You do not meet the requirements to get this opt role!");

                    return;
                }
            }

            //Give the user the role
            await user.AddRoleAsync(RoleUtils.GetGuildRole(Context.Guild, optRole.RoleToGiveId));

            //Say to the user that they now have the role
            await Context.Channel.SendMessageAsync(
                $"You now have the **{RoleUtils.GetGuildRole(Context.Guild, optRole.RoleToGiveId).Name}** role, {user.Mention}.");
        }
Esempio n. 3
0
        public async Task RoleGiveRemove(string optRoleName)
        {
            ServerList server = ServerListsManager.GetServer(Context.Guild);

            //Make sure the opt role exists first
            OptRole optRole = server.GetOptRole(optRoleName);

            if (optRole == null)
            {
                await Context.Channel.SendMessageAsync($"There is no opt role with the name '{optRoleName}'.");

                return;
            }

            //Remove it
            server.RoleGives.Remove(optRole);
            ServerListsManager.SaveServerList();

            await Context.Channel.SendMessageAsync($"An opt role with the name `{optRoleName}` was removed.");
        }