public async Task <bool> GrantRolesAsync(ulong userId, IReadOnlySet <DiscordRole> discordRoles)
        {
            DiscordGuild guild = await _guildProvider.GetCurrentGuildAsync();

            List <DRole> roles = new();

            foreach (DiscordRole discordRole in discordRoles)
            {
                DRole?role = guild.GetRole(discordRole.RoleId);
                if (role == null)
                {
                    _logger.LogWarning("Couldn't map all roles. Please verify your config file");
                    return(false);
                }

                roles.Add(role);
            }

            // TODO: job queue
            Task _ = Task.Run(async() =>
            {
                DiscordMember member = await guild.GetMemberAsync(userId);
                foreach (DRole role in roles)
                {
                    await member.GrantRoleAsync(role, "Auth");
                }
            });

            return(true);
        }
Esempio n. 2
0
        public async Task DeleteAllUnusedVoiceChannelsAsync()
        {
            DiscordGuild guild = await _guildProvider.GetCurrentGuildAsync();

            DiscordChannel customVoiceCategory = guild.GetChannel(_voiceConfig.ClickChannelId).Parent;

            foreach (DiscordChannel discordChannel in customVoiceCategory.Children)
            {
                await DeleteUnusedVoiceChannelAsync(discordChannel);
            }
        }