Exemple #1
0
        public async Task <bool> IsPluginEnabled(IGuild guild, ModuleInfo moduleInfo)
        {
            var moduleAssemblyName = GetAssemblyEntityByModule(moduleInfo);

            if (moduleAssemblyName.Assembly.GetName().Name.SanitizAssembly() == "HeroBot.Plugins.HeroBot")
            {
                return(true);
            }
            PluginEnabling[] cv;
            var rd = await _simpleCacheImplementation.GetValueAsync($"guildPluginsCache-{guild.Id}");

            if (!rd.HasValue)
            {
                var connection = _database.GetDbConnection();
                cv = (await connection.QueryAsync <PluginEnabling>(GetGuildEnabledPlugins, new
                {
                    guild = (long)guild.Id
                })).ToArray();
                await _simpleCacheImplementation.CacheValueAsync($"guildPluginsCache-{guild.Id}", JsonConvert.SerializeObject(cv));
            }
            else
            {
                cv = JsonConvert.DeserializeObject <PluginEnabling[]>(rd);
            }
            if (!cv.Any(x => x.Plugin == moduleAssemblyName.Assembly.GetName().Name.SanitizAssembly()))
            {
                return(false);
            }
            return(true);
        }
Exemple #2
0
        internal async Task <RPUser> GetRPUser(IUser user)
        {
            var cacheResult = await _cache.GetValueAsync($"rp-user-{user.Id}");

            if (cacheResult.HasValue)
            {
                return(JsonConvert.DeserializeObject <RPUser>(cacheResult));
            }
            else
            {
                using var connection = _database.GetDbConnection();
                var val = await connection.QueryAsync <RPUser>(GetUserSql, new { Id = user.Id.ToString() });

                if (val.Any())
                {
                    await _cache.CacheValueAsync($"rp-user-{user.Id}", JsonConvert.SerializeObject(val.First()));

                    return(val.First());
                }
                else
                {
                    return(null);
                }
            }
        }