Exemplo n.º 1
0
        public async Task WithDrawAsync([Summary("送り先のアドレス")] string address, [Summary("金額")] decimal amount = decimal.MinusOne, [Remainder] string comment = null)
        {
            var account = TippingManager.GetAccountName(Context.User);
            await TippingManager.EnsureAccountAsync(account).ConfigureAwait(false);

            var balance1 = decimal.Parse(await TippingManager.InvokeMethodAsync("getbalance", account, 1).ConfigureAwait(false));
            var queued   = TippingManager.GetCollection().Find(x => x.From == Context.User.Id).Sum(x => x.Amount);

            if (amount > 0 && amount < balance1 - queued)
            {
                var txid = await TippingManager.InvokeMethodAsync("sendfrom", account, address, amount == decimal.MinusOne?decimal.Parse(await TippingManager.InvokeMethodAsync("getbalance", account).ConfigureAwait(false)) : amount).ConfigureAwait(false);
                await ReplyAsync
                (
                    message : Context.User.Mention,
                    embed :
                    new EmbedBuilder()
                    .WithTitle("出金完了")
                    .WithDescription($"```{address}```\nに出金しました。")
                    .WithCurrentTimestamp()
                    .WithColor(Colors.Green)
                    .WithFooter(EmbedManager.CurrentFooter)
                    .WithAuthor(Context.User)
                    .AddInlineField("金額", $"{amount:N8} ZNY")
                    .AddInlineField("トランザクションID", $"```{txid}```")
                ).ConfigureAwait(false);

                if (TippingManager.GetIsAndroidMode(Context.User))
                {
                    await ReplyAsync($"```{txid}```");
                }
            }
        }
Exemplo n.º 2
0
        public async Task BalanceAsync([Remainder] string comment = null)
        {
            var account = TippingManager.GetAccountName(Context.User);
            var address = await TippingManager.EnsureAccountAsync(account).ConfigureAwait(false);

            var earned = decimal.Zero;
            await Task.WhenAll(TippingManager.GetCollection().Find(x => x.To == Context.User.Id).Select(async x =>
            {
                try
                {
                    earned       += x.Amount;
                    var from      = DiscordClient.GetUser(x.From);
                    var txid      = await TippingManager.InvokeMethodAsync("sendfrom", TippingManager.GetAccountName(from), address, x.Amount).ConfigureAwait(false);
                    var isDeleted = await TippingManager.DeleteRequestAsync(x.Id).ConfigureAwait(false);
                    await RequestLogAsync(new LogMessage(LogSeverity.Verbose, "TippingModule", $"Sent {x.Amount} ZNY from {from.Username}#{from.Discriminator} to {Context.User.Username}#{Context.User.Discriminator}."));
                }
                catch (Exception ex)
                {
                    await RequestLogAsync(new LogMessage(LogSeverity.Error, "TippingModule", ex.Message, ex));
                }
            }));

            var balance0 = decimal.Parse(await TippingManager.InvokeMethodAsync("getbalance", account, 0).ConfigureAwait(false));
            var balance1 = decimal.Parse(await TippingManager.InvokeMethodAsync("getbalance", account, 1).ConfigureAwait(false));
            var queued   = TippingManager.GetCollection().Find(x => x.From == Context.User.Id).Sum(x => x.Amount);

            await ReplyAsync
            (
                message : Context.User.Mention,
                embed :
                new EmbedBuilder()
                .WithTitle("残高")
                .WithDescription($"{balance0} ZNY")
                .WithCurrentTimestamp()
                .WithColor(Colors.Blue)
                .WithFooter(EmbedManager.CurrentFooter)
                .WithAuthor(Context.User)
                .AddInlineField("利用可能", $"{balance1 - queued:N8} ZNY")
                .AddInlineField("検証待ち", $"{balance0 - balance1:N8} ZNY")
                .AddInlineField("受取待ち", $"{queued:N8} ZNY")
                .AddInlineField("受け取り", $"{earned:N8} ZNY")
            ).ConfigureAwait(false);
        }
Exemplo n.º 3
0
        public async Task DepositAsync([Remainder] string comment = null)
        {
            var address = await TippingManager.EnsureAccountAsync(TippingManager.GetAccountName(Context.User)).ConfigureAwait(false);

            await ReplyAsync
            (
                message : Context.User.Mention,
                embed :
                new EmbedBuilder()
                .WithTitle("入金用アドレス")
                .WithDescription($"```{address}```")
                .WithCurrentTimestamp()
                .WithColor(Colors.Blue)
                .WithFooter(EmbedManager.CurrentFooter)
                .WithAuthor(Context.User)
            ).ConfigureAwait(false);

            if (TippingManager.GetIsAndroidMode(Context.User))
            {
                await ReplyAsync($"```{address}```");
            }
        }
Exemplo n.º 4
0
        public async Task SendAsync([Summary("送り先のユーザー")] IUser user, [Summary("金額")] decimal amount, [Remainder] string comment = null)
        {
            var account = TippingManager.GetAccountName(Context.User);
            var address = await TippingManager.EnsureAccountAsync(TippingManager.GetAccountName(user)).ConfigureAwait(false);

            var balance1 = decimal.Parse(await TippingManager.InvokeMethodAsync("getbalance", account, 1).ConfigureAwait(false));
            var queued   = TippingManager.GetCollection().Find(x => x.From == Context.User.Id).Sum(x => x.Amount);

            if (amount > 0 && amount < balance1 - queued)
            {
                var txid = await TippingManager.InvokeMethodAsync("sendfrom", account, address, amount).ConfigureAwait(false);
                await ReplyAsync
                (
                    message : Context.User.Mention,
                    embed :
                    new EmbedBuilder()
                    .WithTitle("送金完了")
                    .WithDescription($"{user.Mention} に送金しました。")
                    .WithCurrentTimestamp()
                    .WithColor(Colors.Green)
                    .WithFooter(EmbedManager.CurrentFooter)
                    .WithAuthor(Context.User)
                    .WithThumbnailUrl(user.GetAvatarUrl())
                    .AddInlineField("金額", $"{amount:N8} ZNY")
                    .AddInlineField("トランザクションID", $"```{txid}```")
                ).ConfigureAwait(false);

                if (TippingManager.GetIsAndroidMode(Context.User))
                {
                    await ReplyAsync($"```{txid}```");
                }
                var embed =
                    new EmbedBuilder()
                    .WithTitle("送金通知")
                    .WithDescription($"{Context.User.Mention} からの送金を受け取りました。")
                    .WithCurrentTimestamp()
                    .WithColor(Colors.Orange)
                    .WithFooter(EmbedManager.CurrentFooter)
                    .WithAuthor(user)
                    .WithThumbnailUrl(Context.User.GetAvatarUrl())
                    .AddInlineField("金額", $"{amount:N8} ZNY")
                    .AddInlineField("トランザクションID", $"```{txid}```");
                if (!string.IsNullOrEmpty(comment))
                {
                    embed = embed.AddField("コメント", comment);
                }
                var dm = await user.GetOrCreateDMChannelAsync().ConfigureAwait(false);

                await dm.SendMessageAsync
                (
                    text : user.Mention,
                    embed : embed
                ).ConfigureAwait(false);

                if (TippingManager.GetIsAndroidMode(user))
                {
                    await dm.SendMessageAsync($"```{txid}```");
                }
            }
            else
            {
                await ReplyAsync
                (
                    message : Context.User.Mention,
                    embed :
                    new EmbedBuilder()
                    .WithTitle("送金失敗")
                    .WithDescription("送金に失敗しました。残高が不足している可能性があります。")
                    .WithCurrentTimestamp()
                    .WithColor(Colors.Red)
                    .WithFooter(EmbedManager.CurrentFooter)
                    .WithAuthor(Context.User)
                ).ConfigureAwait(false);
            }
            await RequestLogAsync(new LogMessage(LogSeverity.Verbose, "TippingModule", $"Sent {amount:N8} ZNY from {Context.User.Username}#{Context.User.Discriminator} to {user.Username}#{user.Discriminator}.")).ConfigureAwait(false);
        }