private static void AssertConstant(Expr.Main expr, BigInteger value) { Assert.IsNotNull(expr); Assert.IsNotNull(expr.Functions); Assert.IsTrue(expr.IsValid); Assert.IsTrue(expr.Functions.Count >= 1); Assert.IsTrue(expr.Functions.All(f => f.GetType() == typeof(Expr.NumberFunctions.Constant))); Assert.AreEqual(expr.Functions.OfType <Expr.NumberFunctions.Constant>().Aggregate(BigInteger.Zero, (seed, i) => seed + i.Value), value); }
private static void AssertOneConstant(Expr.Main expr, BigInteger value) { Assert.IsNotNull(expr); Assert.IsNotNull(expr.Functions); Assert.IsTrue(expr.IsValid); Assert.AreEqual(expr.Functions.Count, 1); Assert.IsInstanceOfType(expr.Functions[0], typeof(Expr.NumberFunctions.Constant)); var constant = (Expr.NumberFunctions.Constant)expr.Functions[0]; Assert.AreEqual(constant.Value, value); }
private static void AssertOneDice(Expr.Main expr, BigInteger count, BigInteger max) { Assert.IsNotNull(expr); Assert.IsNotNull(expr.Functions); Assert.IsTrue(expr.IsValid); Assert.AreEqual(expr.Functions.Count, 1); Assert.IsInstanceOfType(expr.Functions[0], typeof(Expr.NumberFunctions.Die)); var die = (Expr.NumberFunctions.Die)expr.Functions[0]; Assert.AreEqual(die.Count, count); Assert.AreEqual(die.Max, max); }
public sealed override Result <Unit, string> SetValue(string rawKey, IReadOnlyList <string> optionValues) { if (optionValues.Count == 0) { return(Result <Unit, string> .CreateError(Texts.Error.Commands.Options.NotFoundValue(rawKey))); } if (optionValues.Count >= 2) { return(Result <Unit, string> .CreateError(Texts.Error.Commands.Options.MultipleValues(rawKey))); } var optionValue = optionValues.First(); var d = Expr.Main.Interpret(optionValue); if (!d.HasValue || !d.Value.IsValid) { return(Result <Unit, string> .CreateError(Texts.Error.Commands.Options.InvalidValue(rawKey, optionValue))); } Value = d.Value; return(Result <Unit, string> .CreateValue(Unit.Default)); }
private static void AssertInvalid(Expr.Main expr) { Assert.IsNotNull(expr); Assert.IsFalse(expr.IsValid); }
public async Task StartAsync(ILazySocketMessageChannel channel, ILazySocketUser user, bool force, Expr.Main expr, int maxSize, bool noProgress) { if (channel == null) { throw new ArgumentNullException(nameof(channel)); } if (user == null) { throw new ArgumentNullException(nameof(user)); } await StartAsync(await channel.GetIdAsync(), await user.GetIdAsync(), await user.GetUsernameAsync(), force, expr, maxSize, noProgress); }
public async Task StartAsync(ulong channelId, ulong userId, string username, bool force, Expr.Main expr, int maxSize, bool noProgress) { if (force) { await EndAsync(channelId, userId, true); } using (var context = new MainDbContext(_config)) { var scan = await context.Scans .Where(s => !s.IsArchived) .FirstOrDefaultAsync(s => s.ChannelID == channelId.ToString() && s.ScanStartedUserID == userId.ToString()); if (scan == null) { await AddOrUpdateUserAsync(context, userId, username); var newScan = new Models.Scan { ChannelID = channelId.ToString(), ScanStartedUserID = userId.ToString(), StartedAt = _config.GetUtcNow(), Expr = expr, MaxSize = maxSize, NoProgress = noProgress, }; await context.Scans.AddAsync(newScan); } else { await RespondByCautionAsync("すでに別の集計が行われています。", channelId, userId); return; } await context.SaveChangesAsync(); } await RespondBySayAsync($"{expr.ToString()} の集計が開始されました。", channelId, userId); }