Esempio n. 1
0
    public Dictionary <string, string> RecallOptions(string name)
    {
        var cmd = CreateCommand(@"SELECT opts FROM nquery_queries WHERE name = @name");

        cmd.Parameters.AddWithValue("@name", name);
        return(MiscUtil.ExtractOpts(cmd.ExecuteScalar()?.ToString() ?? ""));
    }
Esempio n. 2
0
        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());
            }
        }
Esempio n. 3
0
    public static Dictionary <string, string> ExtractOrNot(string opts, ref string cmd)
    {
        var options = MiscUtil.ExtractOpts("");

        if (opts.StartsWith("?"))
        {
            options = MiscUtil.ExtractOpts(opts);
        }
        else
        {
            cmd = (opts + " " + cmd).Trim();
        }
        return(options);
    }
Esempio n. 4
0
        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("🆗"));
        }