public async Task RecallQuery(string name, params string[] args) { GuildDatabase db = dsv.GetOrInitDatabase($"dc-{Context.Guild.Id}"); Dictionary <string, string> options; if (name.StartsWith("?")) { options = MiscUtil.ExtractOpts(name); name = args[0]; Array.Copy(args, 1, args, 0, args.Length - 1); } else { options = db.RecallOptions(name); } if (options.ContainsKey("t")) { options.Add("type", options["t"]); } if (!options.ContainsKey("type")) { options.Add("type", "table"); } try { var tt = db.RecallQuery(GuildDatabase.QueryTypeShorthand(options["type"]), name, args); await Context.Message.AddReactionAsync(new Emoji("🆗")); if (tt.Length > 0) { if (options.ContainsKey("nowrap")) { await ReplyAsync(tt); } else { await ReplyAsync($"```\n{tt}\n```"); } } else { await Context.Message.AddReactionAsync(new Emoji("🤔")); } } catch (Exception e) when(e is DbException || e is UserCommandException) { await ReplyAsync(":exclamation: " + e.Message.Replace("SQL logic error\n", "").Trim()); } }
public async Task ListQueries() { GuildDatabase db = dsv.GetOrInitDatabase($"dc-{Context.Guild.Id}"); var names = db.ListQueryNames(); if (names.Length > 0) { await ReplyAsync(String.Join(", ", names)); } else { await Context.Message.AddReactionAsync(new Emoji("â›”")); } }
public async Task DeleteQuery(string name) { GuildDatabase db = dsv.GetOrInitDatabase($"dc-{Context.Guild.Id}"); try { db.DeleteStoredQuery(name); await Context.Message.AddReactionAsync(new Emoji("🆗")); } catch (Exception e) when(e is DbException || e is UserCommandException) { await ReplyAsync(":exclamation: " + e.Message.Replace("SQL logic error\n", "").Trim()); } }
public async Task GenericQuery(string opts, [Remainder] string cmd) { var options = MiscUtil.ExtractOrNot(opts, ref cmd); if (options.ContainsKey("t")) { options.Add("type", options["t"]); } if (!options.ContainsKey("type")) { options.Add("type", "table"); } if (!dsv.Exists($"dc-{Context.Guild.Id}")) { await Context.Message.AddReactionAsync(new Emoji("📡")); } GuildDatabase db = dsv.GetOrInitDatabase($"dc-{Context.Guild.Id}"); var command = db.CreateCommand(cmd); try { var tt = db.Query(GuildDatabase.QueryTypeShorthand(options["type"]), command); await Context.Message.AddReactionAsync(new Emoji("🆗")); if (tt.Length > 0) { if (options.ContainsKey("nowrap")) { await ReplyAsync(tt); } else { await ReplyAsync($"```\n{tt}\n```"); } } else { await Context.Message.AddReactionAsync(new Emoji("🤔")); } } catch (Exception e) when(e is DbException || e is UserCommandException) { await ReplyAsync(":exclamation: " + e.Message.Replace("SQL logic error\n", "").Trim()); } }
public async Task StoreQuery(string opts, string name, [Remainder] string rest) { Dictionary <string, string> options; if (opts.StartsWith("?")) { options = MiscUtil.ExtractOpts(opts); } else { rest = name + " " + rest; name = opts; options = new Dictionary <string, string>(); } GuildDatabase db = dsv.GetOrInitDatabase($"dc-{Context.Guild.Id}"); db.StoreQuery(name, MiscUtil.DictToOpts(options), rest); await Context.Message.AddReactionAsync(new Emoji("🆗")); }