Esempio n. 1
0
        protected TConfig GetMethodConfig <TConfig>(string group, string command) where TConfig : class
        {
            if (ConfigRepository == null)
            {
                throw new InvalidOperationException("Cannot get method config, missing config instance.");
            }

            var config = ConfigRepository.FindConfig(Context.Guild.Id, group, command);

            return(config?.GetData <TConfig>() ?? throw new ConfigException());
        }
Esempio n. 2
0
        public string GetWebUrl(SocketCommandContext context)
        {
            var random = new Random();
            var config = ConfigRepository.FindConfig(context.Guild.Id, "", "channelboardweb").GetData <ChannelboardConfig>();

            var key  = StringHelper.CreateRandomString(random.Next(10, 50));
            var item = new ChannelboardWebCacheItem()
            {
                GuildID = context.Guild.Id, UserID = context.User.Id
            };

            Cache.Set(key, item, DateTimeOffset.Now.AddHours(1));
            return(string.Format(config.WebUrl, $"?key={key}"));
        }
Esempio n. 3
0
        public string GetRandomFile(SocketGuild guild, string category)
        {
            var config     = ConfigRepository.FindConfig(guild.Id, "", category);
            var configData = config.GetData <MemeImagesConfig>();

            var files = Directory.GetFiles(configData.Path)
                        .Where(file => configData.AllowedImageTypes.Any(type => type == Path.GetExtension(file)))
                        .ToList();

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

            var randomValue = Random.Next(files.Count);

            return(files[randomValue]);
        }
Esempio n. 4
0
        private void ValidateSubjects(bool selfunverify, List <string> subjects, SocketGuild guild)
        {
            if (!selfunverify || subjects?.Count <= 0)
            {
                return;
            }

            var config = ConfigRepository.FindConfig(guild.Id, "selfunverify", "").GetData <SelfUnverifyConfig>();

            if (subjects.Count > config.MaxSubjectsCount)
            {
                throw new ValidationException($"Je možné si ponechat maximálně {config.MaxSubjectsCount} rolí.");
            }

            var invalidSubjects = subjects
                                  .Select(o => o.ToLower())
                                  .Where(subject => !config.Subjects.Contains(subject))
                                  .ToArray();

            if (invalidSubjects.Length > 0)
            {
                throw new ValidationException($"`{string.Join(", ", invalidSubjects)}` nejsou předmětové role.");
            }
        }