private void GetAllUser(object source, OnGetUserEventArgs args) { if (!args.Update) { foreach (string name in args.Users) { if (!OnlineUsers.Any(u => u.Name == name)) { MainDispatcher.Invoke(() => { OnlineUsers.Add(new User { Name = name }); }); } } } else { if (args.AddUser) { MainDispatcher.Invoke(() => { OnlineUsers.Add(new User { Name = args.User }); }); } else { try { var user = OnlineUsers.FirstOrDefault(u => u.Name == args.User); MainDispatcher.Invoke(() => { OnlineUsers.Remove(user); }); } catch { } } } }
/// <summary> /// Try to add user to Online List, if already exists, find him and return /// </summary> /// <param name="chatLine">Full chat line</param> /// <returns>Sender user</returns> public User JoinUser(string chatLine) { string username = Parsing.ParseUsername(chatLine); long userId = Parsing.ParseUserId(chatLine); if (!OnlineUsers.Any(x => x.Username == username)) { // User is not in the list var newUser = new User(username) { ID = userId }; newUser = _botDataManager.LoadUserData(newUser); OnlineUsers.Add(newUser); OnUserJoined?.Invoke(this, new OnUserArgs { User = newUser }); _logger.LogInformation("[JOIN] {name} joined the broadcast!", username); return(newUser); } return(FindOnlineUser(username)); }