Extended the command interface so it passes in the user's DB entry. Just avoids having to look it up again if you're doing DB operations involving the user

This commit is contained in:
barelyprofessional
2024-08-10 00:27:06 +08:00
parent a67641a14d
commit 5d1334d2b3
7 changed files with 19 additions and 17 deletions

View File

@@ -15,16 +15,16 @@ public class WhoisCommand : ICommand
public bool HideFromHelp => false;
public UserRight RequiredRight => UserRight.Guest;
public async Task RunCommand(ChatBot botInstance, MessageModel message, GroupCollection arguments, CancellationToken ctx)
public async Task RunCommand(ChatBot botInstance, MessageModel message, UserDbModel user, GroupCollection arguments, CancellationToken ctx)
{
await using var db = new ApplicationDbContext();
var query = arguments["user"].Value.TrimStart('@').TrimEnd(',').TrimEnd();
var user = await db.Users.FirstOrDefaultAsync(u => u.KfUsername == query, cancellationToken: ctx);
if (user == null)
var queryUser = await db.Users.FirstOrDefaultAsync(u => u.KfUsername == query, cancellationToken: ctx);
if (queryUser == null)
{
botInstance.SendChatMessage($"Requested user '{query}' does not exist. (Note this is case-sensitive)", true);
return;
}
botInstance.SendChatMessage($"@{message.Author.Username}, {user.KfUsername}'s ID is {user.KfId}", true);
botInstance.SendChatMessage($"@{message.Author.Username}, {queryUser.KfUsername}'s ID is {queryUser.KfId}", true);
}
}