mirror of
https://github.com/barelyprofessional/KfChatDotNet.git
synced 2026-05-02 04:22:04 -04:00
Renamed the bot from KickBot -> ChatBot and removed the reference to Kick in the project name
This commit is contained in:
30
KfChatDotNetBot/Commands/WhoisCommand.cs
Normal file
30
KfChatDotNetBot/Commands/WhoisCommand.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using System.Text.RegularExpressions;
|
||||
using KfChatDotNetBot.Models.DbModels;
|
||||
using KfChatDotNetWsClient.Models.Events;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace KfChatDotNetBot.Commands;
|
||||
|
||||
public class WhoisCommand : ICommand
|
||||
{
|
||||
public List<Regex> Patterns => [
|
||||
new Regex("^whois (?<user>.+)")
|
||||
];
|
||||
|
||||
public string HelpText => "Lookup user IDs by username";
|
||||
public bool HideFromHelp => false;
|
||||
public UserRight RequiredRight => UserRight.Guest;
|
||||
|
||||
public async Task RunCommand(ChatBot botInstance, MessageModel message, 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)
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user