예제 #1
0
        public async Task SetValueAsync(GlobalConfigItems key, string data)
        {
            Configuration[key.ToString()] = data;

            using var scope      = ServiceProvider.CreateScope();
            using var repository = scope.ServiceProvider.GetService <IGrillBotRepository>();

            var item = await repository.GlobalConfigRepository.GetItemAsync(key);

            if (item == null)
            {
                item = new GlobalConfigItem()
                {
                    Key   = key.ToString(),
                    Value = data
                };

                await repository.AddAsync(item);
            }
            else
            {
                item.Value = data;
            }

            await repository.CommitAsync();
        }
예제 #2
0
        public async Task <string> GetItemAsync(GlobalConfigItems itemKey)
        {
            var key    = itemKey.ToString();
            var result = await Context.GlobalConfig
                         .SingleOrDefaultAsync(o => o.Key == key);

            return(result?.Value);
        }
예제 #3
0
        public async Task SetAsync(GlobalConfigItems key, string value)
        {
            if (string.Equals(value, "null", StringComparison.InvariantCultureIgnoreCase))
            {
                value = null;
            }

            await ConfigurationService.SetValueAsync(key, value);

            await ReplyAsync("Konfigurace uložena");
        }
예제 #4
0
        public async Task GetAsync(GlobalConfigItems key)
        {
            var value = ConfigurationService.GetValue(key);

            if (string.IsNullOrEmpty(value))
            {
                value = "null";
            }

            if (value.Length >= Discord.DiscordConfig.MaxMessageSize)
            {
                using var stream = new MemoryStream(Encoding.UTF8.GetBytes(value));
                await Context.Channel.SendFileAsync(stream, $"{key}.txt");

                return;
            }

            await ReplyAsync($"```\n{value}```");
        }
예제 #5
0
        public async Task UpdateItemAsync(GlobalConfigItems item, string value)
        {
            var key = item.ToString();

            var result = await Context.GlobalConfig
                         .SingleOrDefaultAsync(o => o.Key == key);

            if (result == null)
            {
                result = new GlobalConfigItem()
                {
                    Key   = key,
                    Value = value
                };

                Context.GlobalConfig.Add(result);
            }
            else
            {
                result.Value = value;
            }

            await Context.SaveChangesAsync();
        }
예제 #6
0
 public Task <GlobalConfigItem> GetItemAsync(GlobalConfigItems key)
 {
     return(Context.GlobalConfig.AsQueryable()
            .SingleOrDefaultAsync(o => o.Key == key.ToString()));
 }
예제 #7
0
 public string GetValue(GlobalConfigItems key)
 {
     return(Configuration[key.ToString()]);
 }