Exemplo n.º 1
0
        private async Task <ITextChannel> GetReportChannelAsync(SocketGuild guild)
        {
            // Attempts to get text channel from database entry.
            var record = await CoreSettings.GetOrCreateGuildSettingsAsync(guild).ConfigureAwait(false);

            var reportChannel = guild.GetTextChannel(record.ReportChannel);

            if (reportChannel != null)
            {
                return(reportChannel);
            }

            // Attempts to get text channel by name.
            var searchChannel = guild.TextChannels.FirstOrDefault(x => x.Name.ToLower().Contains(ReportChannelName));

            if (searchChannel != null)
            {
                record.ReportChannel = searchChannel.Id;
                await CoreSettings.SaveRepositoryAsync().ConfigureAwait(false);

                return(searchChannel);
            }

            // Attempts to create a new text channel.
            var newChannel = await guild.CreateTextChannelAsync(ReportChannelName).ConfigureAwait(false);

            await newChannel.AddPermissionOverwriteAsync(guild.EveryoneRole,
                                                         new OverwritePermissions(viewChannel : PermValue.Deny)).ConfigureAwait(false);

            var modRoles = await GetModeratorRolesAsync(guild).ConfigureAwait(false);

            foreach (var modRole in modRoles)
            {
                await newChannel.AddPermissionOverwriteAsync(modRole,
                                                             new OverwritePermissions(viewChannel : PermValue.Allow)).ConfigureAwait(false);
            }
            return(newChannel);
        }
Exemplo n.º 2
0
 private async Task <string> GetCommandPrefixAsync(SocketGuild guild) => guild == null
     ? "!"
     : (await CoreSettings.GetOrCreateGuildSettingsAsync(guild).ConfigureAwait(false))?.CommandPrefix;
Exemplo n.º 3
0
        private async Task <IEnumerable <SocketRole> > GetModeratorRolesAsync(SocketGuild guild)
        {
            var record = await CoreSettings.GetOrCreateGuildSettingsAsync(guild).ConfigureAwait(false);

            return(guild.Roles.Where(x => x.Permissions.Has(record.ModeratorPermission)));
        }