public IrcUser GetOrCreateUser(string nickName, string channelName) { var dbuser = _database.Table<UserDatabaseEntity>().Where(u => u.NickName.Equals(nickName.ToLower()) && u.Channel.Equals(channelName.ToLower())).FirstOrDefault(); if (dbuser == null) { //_logger.Write($"Creating new user {nickName} on {channelName}"); var user = new IrcUser { Nick = nickName, Channel = channelName, AccessLevel = nickName.Equals(_botOwner) ? 1000 : 0, IsModerator = false }; SaveUser(user); return user; } //_logger.Write($"Loaded user {nickName} on {channelName}"); return new IrcUser { Nick = dbuser.NickName, Channel = dbuser.Channel, AccessLevel = nickName.Equals(_botOwner) ? 1000 : dbuser.AccessLevel, IsModerator = false }; }
public void RemoveUser(IrcUser user) { if (Users.Any(u => u.Nick.Equals(user.Nick))) { Users.RemoveAll(u => u.Nick.Equals(user.Nick)); } }
public void AddUser(IrcUser user) { if (!Users.Any(u => u.Nick.Equals(user.Nick))) { Users.Add(user); } }
public void UpdateUser(IrcUser user) { var userInfo = Users.Find(u => u.Nick.Equals(user.Nick)); if (userInfo != null) { Users.Remove(userInfo); } Users.Add(user); }
public void SaveUser(IrcUser user) { var dbuser = _database.Table<UserDatabaseEntity>().Where(u => u.NickName.Equals(user.Nick.ToLower()) && u.Channel.Equals(user.Channel.ToLower())).FirstOrDefault(); if (dbuser != null) { dbuser.NickName = user.Nick; dbuser.AccessLevel = user.Nick.Equals(_botOwner) ? 1000 : user.AccessLevel; dbuser.Channel = user.Channel; _database.Update(dbuser); } else { dbuser = new UserDatabaseEntity { NickName = user.Nick, Channel = user.Channel, AccessLevel = user.Nick.Equals(_botOwner) ? 1000 : user.AccessLevel }; _database.Insert(dbuser); } }