Exemplo n.º 1
0
        public void AllZero()
        {
            const uint a   = 0;
            var        str = a.MeaninglessString();

            Console.WriteLine(str);
            var b = FriendlyId32.Parse(str);

            Assert.IsNotNull(b);
            Assert.AreEqual(a, b.Value.Value);
        }
Exemplo n.º 2
0
 public void ParseInvalid()
 {
     Assert.IsNull(FriendlyId32.Parse("aaaryc-racnes"));
     Assert.IsNull(FriendlyId32.Parse("molaaa-racnes"));
     Assert.IsNull(FriendlyId32.Parse("molryc-aaanes"));
     Assert.IsNull(FriendlyId32.Parse("molryc-racaaa"));
     Assert.IsNull(FriendlyId32.Parse("molrycracten"));
     Assert.IsNull(FriendlyId32.Parse("hello"));
     Assert.IsNull(FriendlyId32.Parse("hello-world"));
     Assert.IsNull(FriendlyId32.Parse("molryc-world"));
 }
Exemplo n.º 3
0
        public void Parse()
        {
            var str = "lomryc-racnes";
            var fid = FriendlyId32.Parse(str);

            Assert.IsTrue(fid.HasValue);
            Assert.AreEqual(str, fid.ToString());

            Console.WriteLine(str);
            Console.WriteLine(fid.Value.Value);
            Console.WriteLine(fid.ToString());
        }
Exemplo n.º 4
0
        public async Task CancelReminder([NotNull] string id)
        {
            var parsed = FriendlyId32.Parse(id);

            if (!parsed.HasValue)
            {
                await TypingReplyAsync("Invalid ID");

                return;
            }

            if (await _reminders.Delete(parsed.Value.Value))
            {
                await TypingReplyAsync($"Deleted reminder `{id}`");
            }
            else
            {
                await TypingReplyAsync($"I can't find a reminder with id `{id}`");
            }
        }
Exemplo n.º 5
0
        public async Task Confirm([NotNull] string input)
        {
            var fid = FriendlyId32.Parse(input);

            if (!fid.HasValue)
            {
                await TypingReplyAsync("Invalid ID `{id}`");

                return;
            }

            var transactions = await(await _pending.Get(debtId: fid.Value.Value)).ToArray();

            if (transactions.Length == 0)
            {
                await TypingReplyAsync($"Cannot find a transaction with ID `{fid}`");

                return;
            }

            if (transactions.Length > 1)
            {
                await TypingReplyAsync($"Found multiple transactions with ID `{fid}`! This is probably an error, please report it.");

                return;
            }

            var transaction = transactions[0];

            if (transaction.ToId != Context.User.Id)
            {
                await TypingReplyAsync("You cannot confirm this transaction");

                return;
            }

            var result = await _pending.ConfirmPending(fid.Value.Value);

            switch (result)
            {
            case ConfirmResult.Confirmed:
                await TypingReplyAsync($"Confirmed {TransactionFormatting.FormatTransaction(this, transaction)}");

                break;

            case ConfirmResult.AlreadyDenied:
                await TypingReplyAsync("This transaction has already been denied and cannot be confirmed");

                break;

            case ConfirmResult.AlreadyConfirmed:
                await TypingReplyAsync("This transaction has already been confirmed");

                break;

            case ConfirmResult.IdNotFound:
                await TypingReplyAsync($"Cannot find a transaction with ID `{fid}`! This is probably an error, please report it.");

                break;

            default:
                await TypingReplyAsync($"Unknown transaction state `{result}`! This is probably an error, please report it.");

                throw new ArgumentOutOfRangeException();
            }
        }