public async Task ConfigureDefaultPrefixesAsync(CommandContext ctx, [RemainingText, Description("Whether default prefixes are to be enabled.")] bool enable) { var gid = (long)ctx.Guild.Id; var gpfx = this.Database.Prefixes.SingleOrDefault(x => x.GuildId == gid); if (gpfx == null) { gpfx = new DatabasePrefix { GuildId = gid, Prefixes = new string[] { }, EnableDefault = enable }; this.Database.Prefixes.Add(gpfx); } else { gpfx.EnableDefault = enable; this.Database.Prefixes.Update(gpfx); } await this.Database.SaveChangesAsync(); await ctx.RespondAsync($"{DiscordEmoji.FromName(ctx.Client, ":msokhand:")} Setting saved."); }
public async Task AddPrefixAsync(CommandContext ctx, [Description("Prefix to add to this guild's prefixes.")] string prefix) { var gid = (long)ctx.Guild.Id; var gpfx = this.Database.Prefixes.SingleOrDefault(x => x.GuildId == gid); if (gpfx?.EnableDefault != false && this.Bot.Configuration.Discord.DefaultPrefixes.Contains(prefix)) { await ctx.RespondAsync($"{DiscordEmoji.FromName(ctx.Client, ":msraisedhand:")} Cannot add default prefix."); return; } if (gpfx == null) { gpfx = new DatabasePrefix { GuildId = gid, Prefixes = new[] { prefix }, EnableDefault = true }; this.Database.Prefixes.Add(gpfx); } else if (!gpfx.Prefixes.Contains(prefix)) { gpfx.Prefixes = gpfx.Prefixes.Concat(new[] { prefix }).ToArray(); this.Database.Prefixes.Update(gpfx); } await this.Database.SaveChangesAsync(); await ctx.RespondAsync($"{DiscordEmoji.FromName(ctx.Client, ":msokhand:")} Prefix added."); }