public Challenge(ulong id, string name, string checkIndicator, IReadOnlyList <IReadOnlyDictionary <string, Value> > inputs, IReadOnlyList <IReadOnlyDictionary <string, Value> > outputs, DateTime?endTime, ChallengeDifficulty difficulty, string description, bool shuffle, ScoreMode scoreMode) { Id = id; Name = name; CheckIndicator = checkIndicator; Inputs = inputs; Outputs = outputs; EndTime = endTime; Difficulty = difficulty; Description = description; ScoreMode = scoreMode; ShuffleTests = shuffle; }
public async Task SetDifficulty(ChallengeDifficulty difficulty) { var current = await _challenges.GetCurrentChallenge(); if (current == null) { await ReplyAsync("There is no current challenge"); } else { await _challenges.ChangeChallengeDifficulty(current, difficulty); await ReplyAsync($"Changed difficulty from `{current.Difficulty}` to `{difficulty}`"); } }
public async Task ChangeChallengeDifficulty(Challenge challenge, ChallengeDifficulty difficulty) { // Set status to "Running" and end time to an appropriate offset from now await using var cmd = _database.CreateCommand(); cmd.CommandText = "UPDATE Challenges SET Difficulty = @Difficulty WHERE ID = @ID"; cmd.Parameters.Add(new SqliteParameter("@ID", DbType.UInt64) { Value = challenge.Id }); cmd.Parameters.Add(new SqliteParameter("@Difficulty", DbType.UInt64) { Value = (ulong)difficulty }); await cmd.ExecuteNonQueryAsync(); }
public async Task Create(string title, string description, ChallengeDifficulty difficulty, string url) { if (!Uri.TryCreate(url, UriKind.Absolute, out var result)) { await ReplyAsync("Invalid URL format"); return; } if (result.Host != "gist.githubusercontent.com") { await ReplyAsync("URL must begin with `gist.githubusercontent.com`"); return; } Data?data; try { using var wc = new WebClient(); var json = wc.DownloadString(result); data = JsonConvert.DeserializeObject <Data>(json, new JsonSerializerSettings { Converters = new JsonConverter[] { new YololValueConverter() }, FloatParseHandling = FloatParseHandling.Decimal }); } catch (Exception e) { await ReplyAsync("Failed: " + e.Message.Substring(0, Math.Min(1000, e.Message.Length))); return; } if (data == null) { await ReplyAsync("Test cases cannot be null"); return; } if (data.In == null) { await ReplyAsync("Input values cannot be null"); return; } if (data.Out == null) { await ReplyAsync("Output values cannot be null"); return; } var c = new Challenge(0, title, "done", data.In, data.Out, null, difficulty, description, data.Shuffle ?? true, data.Mode ?? ScoreMode.BasicScoring); await _challenges.Create(c); await ReplyAsync("Challenge added to queue"); }