Пример #1
0
        public async Task HandleManualPeakCommandAsync(string platform, string user, int season, int peak)
        {
            ManualPeakOverride manual = _db.ManualPeakOverrides.Find(platform, user, season);

            if (manual is null)
            {
                manual = new ManualPeakOverride
                {
                    Platform = platform,
                    User     = user,
                    Season   = season,
                    Peak     = peak
                };

                _db.Add(manual);
                await _db.SaveChangesAsync().ConfigureAwait(false);

                await Context.Channel.SendMessageAsync("Added manual peak");
            }
            else
            {
                manual.Peak             = peak;
                _db.Entry(manual).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
                await _db.SaveChangesAsync().ConfigureAwait(false);

                await Context.Channel.SendMessageAsync("Modified manual peak");
            }
        }
Пример #2
0
        private async Task HandleCustomCommandAddAsync(string key, string value)
        {
            CustomCommand cc = _db.CustomCommands.FirstOrDefault(x => x.Command == key);

            if (cc != null)
            {
                await Context.Channel.SendMessageAsync($"Custom Command: {key} already exists").ConfigureAwait(false);
            }
            else
            {
                // TODO: ADD Validation so that it can't overlap with real commands.
                if (_commandHandler.ContainsCommand(key))
                {
                    return;
                }

                cc = new CustomCommand
                {
                    Command     = key,
                    ReturnValue = value
                };
                _db.Add(cc);
                await _db.SaveChangesAsync();

                await Context.Channel.SendMessageAsync($"Custom Command: {key} was created.").ConfigureAwait(false);
            }
        }
Пример #3
0
        private async Task HandleConfigSubCommandAsync(string sub, string key, string value)
        {
            DBConfigSettings config = _db.ConfigSettings.FirstOrDefault(config => config.Subsection == sub && config.Key == key);

            if (config != null)
            {
                if (string.IsNullOrEmpty(value))
                {
                    _db.Remove(config);
                    await Context.Channel.SendMessageAsync("Deleted DB Setting");

                    await _db.SaveChangesAsync().ConfigureAwait(false);

                    return;
                }

                config.Value            = value;
                _db.Entry(config).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
            }
            else
            {
                if (string.IsNullOrEmpty(value))
                {
                    await Context.Channel.SendMessageAsync("New DB Setting cannot have blank value.\r\n" +
                                                           "Syntax: !config section key value\r\n" +
                                                           "Example: !config Channels Log #test-channel");

                    return;
                }

                config = new DBConfigSettings
                {
                    Subsection = sub,
                    Key        = key,
                    Value      = value
                };

                _db.ConfigSettings.Add(config);
            }

            await _db.SaveChangesAsync().ConfigureAwait(false);

            await Context.Channel.SendMessageAsync("Updated DB Setting");
        }