Esempio n. 1
0
        public async Task <TimeSpan?> GetCooldownSpan(ICommandActor actor, string commandId)
        {
            var roles = await m_PermissionRoleStore.GetRolesAsync(actor);

            if (roles == null || roles.Count == 0)
            {
                return(null);
            }

            TimeSpan?span     = null;
            int      priority = 0;

            foreach (var role in roles)
            {
                try
                {
                    // Skip as result won't matter
                    if (span.HasValue && priority >= role.Priority)
                    {
                        continue;
                    }

                    var data =
                        (await m_PermissionRolesDataStore.GetRoleDataAsync <List <object> >(role.Id,
                                                                                            "cooldowns"))?.OfType <Dictionary <object, object> >();

                    if (data == null)
                    {
                        continue;
                    }

                    foreach (var dict in data)
                    {
                        var currentSpan = dict.ToObject <CooldownSpan>();

                        if (currentSpan.Command.Equals(commandId, StringComparison.OrdinalIgnoreCase))
                        {
                            span     = currentSpan.GetParsedCooldown();
                            priority = role.Priority;
                        }
                    }
                }
                catch (Exception ex)
                {
                    m_Logger.LogError(ex, "Error occurred while parsing command cooldown");
                    throw;
                }
            }

            return(span);
        }
Esempio n. 2
0
        public Task <T?> GetPersistentDataAsync <T>(string roleId, string key)
        {
            if (string.IsNullOrEmpty(roleId))
            {
                throw new ArgumentNullException(nameof(roleId));
            }

            if (string.IsNullOrEmpty(key))
            {
                throw new ArgumentNullException(nameof(key));
            }

            return(m_PermissionRolesDataStore.GetRoleDataAsync <T>(roleId, key));
        }
Esempio n. 3
0
 public Task <T> GetPersistentDataAsync <T>(string roleId, string key)
 {
     return(m_PermissionRolesDataStore.Roles == null
         ? default
         : m_PermissionRolesDataStore.GetRoleDataAsync <T>(roleId, key));
 }