public async Task SetRerollDuplicates(bool value) { using var db = new DiscordChannelContext(); var existingSettings = await db.ChannelSettings.FirstOrDefaultAsync(cs => cs.ChannelID == Context.Channel.Id); if (existingSettings != null) { existingSettings.RerollDuplicates = value; await db.SaveChangesAsync().ConfigureAwait(false); await Context.Message.AddReactionAsync(new Emoji("π")).ConfigureAwait(false); return; } else { ChannelSettings cs = new ChannelSettings { ChannelID = Context.Channel.Id, RerollDuplicates = value }; db.ChannelSettings.Add(cs); await db.SaveChangesAsync().ConfigureAwait(false); await Context.Message.AddReactionAsync(new Emoji("π")).ConfigureAwait(false); } }
public async Task GetDefaultGame() { using var db = new DiscordChannelContext(); var existingSettings = await db.ChannelSettings.FirstOrDefaultAsync(cs => cs.ChannelID == Context.Channel.Id); if (existingSettings != null) { await ReplyAsync($"Your default game is: {existingSettings.DefaultGame}").ConfigureAwait(false); } else { await ReplyAsync($"Your default game not set.").ConfigureAwait(false); } }
public static async Task <ChannelSettings> GetChannelSettingsAsync(ulong channelID) { using var context = new DiscordChannelContext(); var settings = await context.ChannelSettings.FirstOrDefaultAsync(item => item.ChannelID == channelID); if (settings == null) { settings = new ChannelSettings { ChannelID = channelID, RerollDuplicates = true, DefaultGame = GameName.Ironsworn }; context.ChannelSettings.Add(settings); await context.SaveChangesAsync().ConfigureAwait(false); } return(settings); }
public async Task MainAsync() { using (DiscordChannelContext dbContext = new DiscordChannelContext()) { dbContext.Database.EnsureCreated(); } using (ServiceProvider services = ConfigureServices()) { Console.WriteLine($"Starting TheOracle v{Assembly.GetEntryAssembly().GetName().Version}"); var client = services.GetRequiredService <DiscordSocketClient>(); client.Log += LogAsync; services.GetRequiredService <CommandService>().Log += LogAsync; #nullable enable string?token = Environment.GetEnvironmentVariable("DiscordToken"); if (token == null) { token = services.GetRequiredService <IConfigurationRoot>().GetSection("DiscordToken").Value; } #nullable disable
public static async Task <ChannelSettings> GetChannelSettingsAsync(ulong channelID) { using var context = new DiscordChannelContext(); return(await context.ChannelSettings.FirstOrDefaultAsync(item => item.ChannelID == channelID)); }