add more options to /quote

This commit is contained in:
Elijah R 2024-04-03 16:15:37 -04:00
parent 7110ebaac3
commit a54b42ee67
3 changed files with 18 additions and 6 deletions

View file

@ -9,4 +9,5 @@ public class ChatlogQuery
public int? Count { get; set; }
public bool Random { get; set; }
public string? Regex { get; set; }
public string[]? CustomWhere { get; set; }
}

View file

@ -103,6 +103,8 @@ public class Database
where.Add("message REGEXP @regex");
cmd.Parameters.AddWithValue("@regex", q.Regex);
}
if (q.CustomWhere != null)
where.AddRange(q.CustomWhere);
if (where.Count > 0)
{
cmd.CommandText += " WHERE " + string.Join(" AND ", where);

View file

@ -198,18 +198,27 @@ public class DiscordCommands : ApplicationCommandModule
}
[SlashCommand("quote", "Quote a user")]
public async Task Quote(InteractionContext ctx, [Option("username", "User to quote")] string username)
public async Task Quote(InteractionContext ctx, [Option("username", "User to quote")] string username = "", [Option("guest", "Should the random quote be from a guest only? Only works if username is not specified")] bool guest = false)
{
await ctx.DeferAsync();
var chat = await Program.Database.GetChatlogsAsync(new ChatlogQuery
if (username != "" && guest)
{
await ctx.CreateResponseAsync("You cannot specify both a username and guest.");
return;
}
await ctx.DeferAsync();
var q = new ChatlogQuery
{
Username = username,
Count = 1,
Random = true
});
};
if (username != "")
q.Username = username;
if (guest)
q.CustomWhere = ["username REGEXP '^guest'"];
var chat = await Program.Database.GetChatlogsAsync(q);
if (chat.Length == 0)
{
await ctx.EditResponseAsync(new DiscordWebhookBuilder().WithContent($"@No messages found for {username}"));
await ctx.EditResponseAsync(new DiscordWebhookBuilder().WithContent($"No messages found for {username}"));
return;
}
await ctx.EditResponseAsync(new DiscordWebhookBuilder().WithContent($"> {chat[0].Message}\n\\- {chat[0].Username}, {chat[0].Timestamp} {chat[0].VM}"));