예제 #1
0
        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
            };
        }
예제 #2
0
 public void RemoveUser(IrcUser user)
 {
     if (Users.Any(u => u.Nick.Equals(user.Nick)))
     {
         Users.RemoveAll(u => u.Nick.Equals(user.Nick));
     }
 }
예제 #3
0
 public void AddUser(IrcUser user)
 {
     if (!Users.Any(u => u.Nick.Equals(user.Nick)))
     {
         Users.Add(user);
     }
 }
예제 #4
0
 public void UpdateUser(IrcUser user)
 {
     var userInfo = Users.Find(u => u.Nick.Equals(user.Nick));
     if (userInfo != null)
     {
         Users.Remove(userInfo);
     }
     Users.Add(user);
 }
예제 #5
0
        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);
            }
        }