예제 #1
0
파일: BotGroup.cs 프로젝트: Gohla/Veda
        public bool Equals(IBotGroup other)
        {
            if(ReferenceEquals(other, null))
                return false;

            return
                EqualityComparer<String>.Default.Equals(this.Name, other.Name)
             ;
        }
예제 #2
0
        public static void SetLimit(IContext context, ICommand command, IBotGroup group, ushort limit,
            ulong timespan)
        {
            EnsureAllowGroup(context, group);
            IPermission permission = context.Bot.Permission.GetPermission(command, group);

            permission.Limit = limit;
            permission.Timespan = TimeSpan.FromMilliseconds(timespan);
        }
예제 #3
0
파일: BotGroup.cs 프로젝트: Gohla/Veda
        public int CompareTo(IBotGroup other)
        {
            if(ReferenceEquals(other, null))
                return 1;

            int result = 0;
            result = this.Name.CompareTo(other.Name);
            return result;
        }
예제 #4
0
파일: Permission.cs 프로젝트: Gohla/Veda
        public Permission(IStorage storage, String name, IBotGroup group)
        {
            _storage = storage;
            Name = name;
            Group = group;

            _allowed = _storage.Get<NullableRef<bool>>(Group.Name, Name, ALLOWED_QUALIFIER);
            _limit = _storage.Get<NullableRef<ushort>>(Group.Name, Name, LIMIT_QUALIFIER);
            _timespan = _storage.Get<NullableRef<TimeSpan>>(Group.Name, Name, TIMESPAN_QUALIFIER);
        }
예제 #5
0
        public static void RemoveAllowed(IContext context, ICommand command, IBotGroup group)
        {
            EnsureAllowGroup(context, group);
            IPermission permission = context.Bot.Permission.GetPermission(command, group);

            if(!permission.HasAllowed)
                throw new InvalidCastException("No allowed permission is set for given command and group.");

            permission.HasAllowed = false;
        }
예제 #6
0
        public static void SetGroup(IContext context, IBotUser botUser, IBotGroup group)
        {
            EnsureIdentified(context);

            if(context.User.Equals(botUser))
                throw new InvalidOperationException("Cannot set your own group.");

            if(botUser.Group.IsMoreOrSamePrivileged(context.User.Group))
                throw new InvalidOperationException("Cannot set group for users that have the same or more privileges than yourself.");

            if(group.IsMoreOrSamePrivileged(context.User.Group))
                throw new InvalidOperationException("Cannot set group to one that has the same or more privileges than yourself.");

            botUser.Group = group;
        }
예제 #7
0
파일: BotGroup.cs 프로젝트: Gohla/Veda
 public bool IsMorePrivileged(IBotGroup other)
 {
     return this.PrivilegeLevel > other.PrivilegeLevel;
 }
예제 #8
0
파일: BotUser.cs 프로젝트: Gohla/Veda
 public BotUser(String username, String password, IBotGroup group, bool hash = true)
 {
     Username = username;
     HashedPassword = hash ? PasswordHash.CreateHash(password) : password;
     Group = group;
 }
예제 #9
0
 private static void EnsureAllowGroup(IContext context, IBotGroup group)
 {
     if(group.IsMoreOrSamePrivileged(context.User.Group))
         throw new InvalidOperationException("Cannot change permissions for a group with the same or more privileges than yours.");
 }
예제 #10
0
        public static void SetAllowed(IContext context, ICommand command, IBotGroup group, bool allowed)
        {
            EnsureAllowGroup(context, group);

            context.Bot.Permission.GetPermission(command, group).Allowed = allowed;
        }