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); }
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); }
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()); }
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); } } }
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); } }
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); } }
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); }
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; } }
private async Task ConfessToGuildAsync(string content, ConfessionType type, SocketGuild guild) => await this.ConfessToGuildAsync(CreateConfessionEmbed(content, type), guild, type);