コード例 #1
0
        private async Task ClearLoggingChannelAsync(ConfessionType type)
        {
            var storage = this.GetServerStorage(Context.Guild.Id);

            storage.ClearNamedID(type.LoggingChannelName);
            await this.ReplyAsync("Channel setting cleared!").ConfigureAwait(true);
        }
コード例 #2
0
        private async Task SetLoggingChannelAsync(ITextChannel channel, ConfessionType type)
        {
            var loggingChannel = channel ?? Context.Channel as ITextChannel;
            var storage        = this.GetServerStorage(Context.Guild.Id);

            storage.SetNamedID(type.LoggingChannelName, loggingChannel.Id);
            await this.ReplyAsync("Channel updated to: " + loggingChannel.Name).ConfigureAwait(true);
        }
コード例 #3
0
        private static Embed CreateConfessionEmbed(string content, ConfessionType type)
        {
            var builder      = new EmbedBuilder();
            var fieldBuilder = new EmbedFieldBuilder
            {
                Name     = type.EmbedTitle,
                Value    = content,
                IsInline = false
            };

            builder.AddField(fieldBuilder);
            return(builder.Build());
        }
コード例 #4
0
        private async Task ConfessToGuildAsync(Embed embed, SocketGuild guild, ConfessionType type)
        {
            var storage          = this.GetServerStorage(guild.Id);
            var publishChannelId = storage.GetNamedID(type.PublishChannelName);
            var loggingChannelId = storage.GetNamedID(type.LoggingChannelName);

            if (ConfessionModule.IsValidChannelId(publishChannelId))
            {
                await ConfessionModule.PublishConfessionAsync(embed, guild, publishChannelId);

                if (ConfessionModule.IsValidChannelId(loggingChannelId))
                {
                    await this.LogConfessionAsync(embed, guild, loggingChannelId);
                }
            }
        }
コード例 #5
0
        private async Task TryToSendConfessionAsync(string content, ConfessionType type)
        {
            var mutualGuilds = this.Context.User.MutualGuilds;

            if (mutualGuilds.Count > 1)
            {
                await this.HandleMutualGuildsAmbiguityAsync(content, mutualGuilds, type);
            }
            else if (mutualGuilds.Count == 1)
            {
                await this.PublishInAllMutualGuildsAsync(mutualGuilds, content, type);
            }
            else
            {
                await this.ReplyAsync(confessionbot_strings.ConfessionBotNoMutualServer);
            }
        }
コード例 #6
0
        private async Task PublishInSpecificGuildAsync(IReadOnlyCollection <SocketGuild> mutualGuilds, string content, ConfessionType type)
        {
            var guilds     = ConfessionModule.ToGuildArray(mutualGuilds);
            var guildIndex = await this.AttemptToGetSpecificGuildAsync(guilds);

            if (ConfessionModule.WithinArrayBounds(guilds, guildIndex))
            {
                await this.ConfessToGuildAsync(content, type, guilds[guildIndex]);

                await this.ReplyAsync(confessionbot_strings.ConfessionBotConfessionSent);
            }
            else
            {
                await this.ReplyAsync(confessionbot_strings.ConfessionBotConfessionFailed);
            }
        }
コード例 #7
0
        private async Task PublishInAllMutualGuildsAsync(IReadOnlyCollection <SocketGuild> mutualGuilds, string content, ConfessionType type)
        {
            var embed = ConfessionModule.CreateConfessionEmbed(content, type);

            foreach (SocketGuild guild in mutualGuilds)
            {
                await this.ConfessToGuildAsync(embed, guild, type);
            }

            await this.ReplyAsync(confessionbot_strings.ConfessionBotConfessionSent);
        }
コード例 #8
0
        private async Task HandleMutualGuildsAmbiguityAsync(string content, IReadOnlyCollection <SocketGuild> mutualGuilds, ConfessionType type)
        {
            // We need to know where to post this confession.
            var choice = await this.AskHowToProceedAsync();

            switch (choice)
            {
            case 1:
                await this.PublishInSpecificGuildAsync(mutualGuilds, content, type);

                break;

            case 2:
                await this.PublishInAllMutualGuildsAsync(mutualGuilds, content, type);

                break;

            case 3:
                await this.ReplyAsync(confessionbot_strings.ConfessionBotConfessionAborted);

                break;

            default:
                break;
            }
        }
コード例 #9
0
 private async Task ConfessToGuildAsync(string content, ConfessionType type, SocketGuild guild)
 => await this.ConfessToGuildAsync(CreateConfessionEmbed(content, type), guild, type);