Esempio n. 1
0
        public bool Equals(IBotGroup other)
        {
            if(ReferenceEquals(other, null))
                return false;

            return
                EqualityComparer<String>.Default.Equals(this.Name, other.Name)
             ;
        }
Esempio n. 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);
        }
Esempio n. 3
0
        public int CompareTo(IBotGroup other)
        {
            if(ReferenceEquals(other, null))
                return 1;

            int result = 0;
            result = this.Name.CompareTo(other.Name);
            return result;
        }
Esempio n. 4
0
        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);
        }
Esempio n. 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;
        }
Esempio n. 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;
        }
Esempio n. 7
0
 public bool IsMorePrivileged(IBotGroup other)
 {
     return this.PrivilegeLevel > other.PrivilegeLevel;
 }
Esempio n. 8
0
 public BotUser(String username, String password, IBotGroup group, bool hash = true)
 {
     Username = username;
     HashedPassword = hash ? PasswordHash.CreateHash(password) : password;
     Group = group;
 }
Esempio n. 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.");
 }
Esempio n. 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;
        }