diff --git a/KfChatDotNetBot/ChatBot.cs b/KfChatDotNetBot/ChatBot.cs index 0b0fce8..1313a66 100644 --- a/KfChatDotNetBot/ChatBot.cs +++ b/KfChatDotNetBot/ChatBot.cs @@ -36,7 +36,8 @@ public class ChatBot private DateTime _lastReconnectAttempt = DateTime.UtcNow; private List _scheduledDeletions = []; private Task _scheduledAutoDeleteTask; - + private List _currentUsersInChat = []; + public ChatBot() { _logger.Info("Bot starting!"); @@ -558,12 +559,13 @@ public class ChatBot } public class SentMessageNotFoundException : Exception; - + private void OnUsersJoined(object sender, List users, UsersJsonModel jsonPayload) { var settings = SettingsProvider.GetMultipleValuesAsync([BuiltIn.Keys.GambaSeshUserId, BuiltIn.Keys.GambaSeshDetectEnabled, BuiltIn.Keys.BotKeesSeen]) .Result; _logger.Debug($"Received {users.Count} user join events"); + _currentUsersInChat.AddRange(users); using var db = new ApplicationDbContext(); foreach (var user in users) { @@ -606,6 +608,7 @@ public class ChatBot private void OnUsersParted(object sender, List userIds) { + _currentUsersInChat.RemoveAll(u => userIds.Contains(u.Id)); var settings = SettingsProvider.GetMultipleValuesAsync([BuiltIn.Keys.GambaSeshUserId, BuiltIn.Keys.GambaSeshDetectEnabled]) .Result; if (userIds.Contains(settings[BuiltIn.Keys.GambaSeshUserId].ToType()) && settings[BuiltIn.Keys.GambaSeshDetectEnabled].ToBoolean()) @@ -653,6 +656,7 @@ public class ChatBot _logger.Error($"Sneedchat disconnected due to {disconnectionInfo.Type}"); _logger.Error($"Close Status => {disconnectionInfo.CloseStatus}; Close Status Description => {disconnectionInfo.CloseStatusDescription}"); _logger.Error(disconnectionInfo.Exception); + _currentUsersInChat.Clear(); if (disconnectionInfo.Exception != null && disconnectionInfo.Exception.Message.Contains("status code '203'")) { _logger.Info("Chat 203'd, getting a new token"); @@ -673,6 +677,11 @@ public class ChatBot KfClient.JoinRoom(roomId); } + public UserModel? FindUserByName(string username) + { + return _currentUsersInChat.FirstOrDefault(u => u.Username.Equals(username, StringComparison.CurrentCulture)); + } + public enum LengthLimitBehavior { // Append … diff --git a/KfChatDotNetBot/Commands/Kasino/LegitCheckCommand.cs b/KfChatDotNetBot/Commands/Kasino/LegitCheckCommand.cs index 554e69a..9ff595b 100644 --- a/KfChatDotNetBot/Commands/Kasino/LegitCheckCommand.cs +++ b/KfChatDotNetBot/Commands/Kasino/LegitCheckCommand.cs @@ -23,6 +23,8 @@ public class LegitCheckCommand : ICommand [ new Regex(@"^legitcheck (?\d+)$", RegexOptions.IgnoreCase), new Regex(@"^legitcheck (?\d+) all$", RegexOptions.IgnoreCase), + new Regex(@"^legitcheck @(?.+) all$", RegexOptions.IgnoreCase), + new Regex(@"^legitcheck @(?.+)$", RegexOptions.IgnoreCase), new Regex(@"^legitcheck$", RegexOptions.IgnoreCase), new Regex(@"^legitcheck all$", RegexOptions.IgnoreCase), ]; @@ -46,15 +48,34 @@ public class LegitCheckCommand : ICommand { await using var db = new ApplicationDbContext(); - var targetUserId = arguments["user_id"].Success - ? int.Parse(arguments["user_id"].Value) - : user.KfId; - var targetUser = await db.Users.FirstOrDefaultAsync(u => u.KfId == targetUserId, ctx); var isAll = message.MessageRaw.EndsWith(" all"); + UserDbModel? targetUser; + if (arguments["username"].Success) + { + var chatUser = botInstance.FindUserByName(arguments["username"].Value); + if (chatUser == null) + { + await botInstance.SendChatMessageAsync( + $"{user.FormatUsername()}, couldn't find that user in chat. They must be present in chat to look up by username.", + true); + return; + } + targetUser = await db.Users.FirstOrDefaultAsync(u => u.KfId == chatUser.Id, ctx); + } + else if (arguments["user_id"].Success) + { + var targetUserId = int.Parse(arguments["user_id"].Value); + targetUser = await db.Users.FirstOrDefaultAsync(u => u.KfId == targetUserId, ctx); + } + else + { + targetUser = await db.Users.FirstOrDefaultAsync(u => u.KfId == user.KfId, ctx); + } + if (targetUser == null) { - await botInstance.SendChatMessageAsync($"{user.FormatUsername()}, the user ID you gave doesn't exist.", + await botInstance.SendChatMessageAsync($"{user.FormatUsername()}, that user doesn't exist.", true); return; }