public bool Equals(IBotGroup other) { if(ReferenceEquals(other, null)) return false; return EqualityComparer<String>.Default.Equals(this.Name, other.Name) ; }
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); }
public int CompareTo(IBotGroup other) { if(ReferenceEquals(other, null)) return 1; int result = 0; result = this.Name.CompareTo(other.Name); return result; }
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); }
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; }
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; }
public bool IsMorePrivileged(IBotGroup other) { return this.PrivilegeLevel > other.PrivilegeLevel; }
public BotUser(String username, String password, IBotGroup group, bool hash = true) { Username = username; HashedPassword = hash ? PasswordHash.CreateHash(password) : password; Group = group; }
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."); }
public static void SetAllowed(IContext context, ICommand command, IBotGroup group, bool allowed) { EnsureAllowGroup(context, group); context.Bot.Permission.GetPermission(command, group).Allowed = allowed; }