Beispiel #1
0
        public async Task Process(SocketUserMessage msg)
        {
            FusionBotConfig cfg = ((FusionBotConfig)Globals.Bot.Config);

            if (!cfg.UserWalletCache.ContainsKey(msg.Author.Id))
            {
                await AccountHelper.CreateNewAccount(msg);
            }
            else
            {
                await new GetBalance(new GetBalanceRequestData
                {
                    AccountIndex = cfg.UserWalletCache[msg.Author.Id].Item1
                },
                                     (GetBalanceResponseData result) =>
                {
                    EmbedBuilder eb = new EmbedBuilder()
                                      .WithAuthor($"Your Tip Jar", Globals.Client.GetUser(msg.Author.Id).GetAvatarUrl())
                                      .WithDescription("Let's see what's going on here")
                                      .WithColor(Color.DarkTeal)
                                      .WithThumbnailUrl(Globals.Client.CurrentUser.GetAvatarUrl());

                    eb.AddField("Address", cfg.UserWalletCache[msg.Author.Id].Item2);
                    eb.AddField($"Unlocked", $"{result.UnlockedBalance.FromAtomicUnits()} xnv");
                    eb.AddField($"Total", $"{result.Balance.FromAtomicUnits()} xnv");

                    Sender.PrivateReply(msg, null, eb.Build()).Wait();
                },
                                     (RequestError e) =>
                {
                    Sender.PrivateReply(msg, "Oof. No good. You are going to have to try again later.").Wait();
                },
                                     cfg.WalletHost, cfg.UserWalletPort).RunAsync();
            }
        }
Beispiel #2
0
        public async Task Process(SocketUserMessage msg)
        {
            FusionBotConfig cfg = ((FusionBotConfig)Globals.Bot.Config);

            await new GetBalance(new GetBalanceRequestData
            {
                AccountIndex = 0
            },
                                 (GetBalanceResponseData result) =>
            {
                EmbedBuilder eb = new EmbedBuilder()
                                  .WithAuthor($"Fusion's Tip Jar", Globals.Client.CurrentUser.GetAvatarUrl())
                                  .WithDescription("Whale or fail?")
                                  .WithColor(Color.DarkTeal)
                                  .WithThumbnailUrl(Globals.Client.CurrentUser.GetAvatarUrl());

                eb.AddField("Address", cfg.UserWalletCache[cfg.BotId].Item2);
                eb.AddField("Unlocked", $"{result.UnlockedBalance.FromAtomicUnits()} xnv");
                eb.AddField("Total", $"{result.Balance.FromAtomicUnits()} xnv");

                Sender.PublicReply(msg, null, eb.Build()).Wait();
            },
                                 (RequestError e) =>
            {
                Sender.PrivateReply(msg, "Oof. No good. You are going to have to try again later.").Wait();
            },
                                 cfg.WalletHost, cfg.UserWalletPort).RunAsync();
        }
Beispiel #3
0
        private async Task SendToUser(SocketUserMessage msg, SocketUser recipient, uint accountIndex, ulong amount)
        {
            FusionBotConfig cfg = ((FusionBotConfig)Globals.Bot.Config);

            await new Transfer(new TransferRequestData
            {
                AccountIndex = accountIndex,
                Destinations = new List <TransferDestination> {
                    new TransferDestination {
                        Amount  = amount,
                        Address = cfg.UserWalletCache[recipient.Id].Item2
                    }
                }
            },
                               (TransferResponseData r) =>
            {
                Sender.SendPrivateMessage(Globals.Client.GetUser(msg.Author.Id), $"You sent {r.Amount.FromAtomicUnits()} xnv to {recipient.Mention} with a fee of {r.Fee.FromAtomicUnits()} xnv\r\n{r.TxHash}").Wait();
                msg.AddReactionAsync(new Emoji("💸"));

                if (recipient.Id != cfg.BotId) //exception thrown if trying to send a DM to fusion, so skip
                {
                    Sender.SendPrivateMessage(Globals.Client.GetUser(recipient.Id), $"{msg.Author.Mention} sent you {r.Amount.FromAtomicUnits()} xnv").Wait();
                }
            },
                               (RequestError e) =>
            {
                Sender.SendPrivateMessage(Globals.Client.GetUser(msg.Author.Id), "Oof. No good. You are going to have to try again later.").Wait();
                msg.AddReactionAsync(new Emoji("🆘"));
            },
                               cfg.WalletHost, cfg.UserWalletPort).RunAsync();
        }
Beispiel #4
0
        public async Task Process(SocketUserMessage msg)
        {
            FusionBotConfig cfg = ((FusionBotConfig)Globals.Bot.Config);

            //can only be run by angrywasp
            //todo: remove hard coded user id
            if (msg.Author.Id != 407511685134549003)
            {
                await Sender.PublicReply(msg, "No rescan for you!");

                return;
            }

            new RescanBlockchain((c) =>
            {
                Sender.PrivateReply(msg, "Rescan of donation wallet complete.").Wait();
            }, (e) =>
            {
                Sender.PrivateReply(msg, "Oof. Couldn't rescan donation wallet.").Wait();
            }, cfg.WalletHost, cfg.DonationWalletPort).RunAsync();

            new RescanBlockchain((c) =>
            {
                Sender.PrivateReply(msg, "Rescan of user wallet complete.").Wait();
            }, (e) =>
            {
                Sender.PrivateReply(msg, "Oof. Couldn't rescan user wallet.").Wait();
            }, cfg.WalletHost, cfg.UserWalletPort).RunAsync();
        }
Beispiel #5
0
        public static async Task ProcessResults(Lottery sender)
        {
            //todo: post results in fusion channel

            ulong tsNow = DateTimeHelper.TimestampNow();
            //save the game in case of dispute or a problem paying out
            string savedGameName = $"{tsNow}.xml";

            new ObjectSerializer().Serialize(sender, savedGameName);

            var n  = sender.Numbers;
            var wn = sender.WinningNumbers;

            FusionBotConfig cfg = ((FusionBotConfig)Globals.Bot.Config);

            //pay minor prizes
            foreach (var w in wn)
            {
                RequestError err = await AccountHelper.PayUser((double)sender.Parameters.MinorPrize, cfg.BotId, n[w]);

                if (err != null)
                {
                    await Sender.SendPrivateMessage(Globals.Client.GetUser(n[w]), $"You just won {sender.Parameters.MinorPrize}xnv in the lottery, but there was a problem with the payout. Please contact an admin and quote number `{tsNow}`");
                }
                else
                {
                    await Sender.SendPrivateMessage(Globals.Client.GetUser(n[w]), $"You just won {sender.Parameters.MinorPrize}xnv in the lottery.");
                }
            }

            float jackpot = sender.JackpotAmount;

            foreach (var w in wn)
            {
                if (sender.JackpotNumber == w)
                {
                    RequestError err = await AccountHelper.PayUser((double)sender.JackpotAmount, cfg.BotId, n[w]);

                    if (err != null)
                    {
                        await Sender.SendPrivateMessage(Globals.Client.GetUser(n[w]), $"You just won the lottery jackpot of {sender.JackpotAmount}xnv, but there was a problem with the payout. Please contact an admin and quote number `{tsNow}`");
                    }
                    else
                    {
                        await Sender.SendPrivateMessage(Globals.Client.GetUser(n[w]), $"You just won the lottery jackpot of {sender.JackpotAmount}xnv.");
                    }

                    jackpot = 0;
                }
            }

            Restart(jackpot);
        }
Beispiel #6
0
        public async Task Process(SocketUserMessage msg)
        {
            FusionBotConfig cfg = ((FusionBotConfig)Globals.Bot.Config);

            if (!cfg.UserWalletCache.ContainsKey(msg.Author.Id))
            {
                await AccountHelper.CreateNewAccount(msg);
            }
            else
            {
                string address = cfg.UserWalletCache[msg.Author.Id].Item2;
                await Sender.PrivateReply(msg, $"`{address}`");
            }
        }
Beispiel #7
0
        public async Task Process(SocketUserMessage msg)
        {
            FusionBotConfig cfg = ((FusionBotConfig)Globals.Bot.Config);

            if (!cfg.UserWalletCache.ContainsKey(msg.Author.Id))
            {
                await AccountHelper.CreateNewAccount(msg);
            }
            else
            {
                uint accountIndex = cfg.UserWalletCache[msg.Author.Id].Item1;

                string address;
                double amount;

                if (!AccountHelper.ParseAddressFromMessage(msg, out address))
                {
                    await Sender.PrivateReply(msg, "Oof. No good. You didn't provide a valid address. :derp:");

                    return;
                }

                if (!AccountHelper.ParseDoubleFromMessage(msg, out amount))
                {
                    await Sender.PrivateReply(msg, "Oof. No good. You need to know how much you want to send. :derp:");

                    return;
                }

                await new Transfer(new TransferRequestData
                {
                    AccountIndex = accountIndex,
                    Destinations = new List <TransferDestination> {
                        new TransferDestination {
                            Amount  = amount.ToAtomicUnits(),
                            Address = address
                        }
                    }
                },
                                   (TransferResponseData r) =>
                {
                    Sender.PrivateReply(msg, $"{r.Amount.FromAtomicUnits()} xnv was sent with a fee of {r.Fee.FromAtomicUnits()} xnv\r\n{r.TxHash}").Wait();
                },
                                   (RequestError e) =>
                {
                    Sender.PrivateReply(msg, "Oof. No good. You are going to have to try again later.").Wait();
                },
                                   cfg.WalletHost, cfg.UserWalletPort).RunAsync();
            }
        }
Beispiel #8
0
        public async Task Process(SocketUserMessage msg)
        {
            FusionBotConfig cfg = ((FusionBotConfig)Globals.Bot.Config);

            if (!cfg.UserWalletCache.ContainsKey(msg.Author.Id))
            {
                await AccountHelper.CreateNewAccount(msg);
            }
            else
            {
                string address;
                if (!AccountHelper.ParseAddressFromMessage(msg, out address))
                {
                    await Sender.PrivateReply(msg, "Oof. No good. You didn't provide a valid address. :derp:");

                    return;
                }

                uint accountIndex = cfg.UserWalletCache[msg.Author.Id].Item1;

                await new SweepAll(new SweepAllRequestData
                {
                    AccountIndex = accountIndex,
                    Address      = address,
                },
                                   (SweepAllResponseData r) =>
                {
                    int numTxs         = r.TxHashList.Count;
                    double totalAmount = 0, totalFee = 0;
                    string txHashList  = string.Empty;

                    for (int i = 0; i < numTxs; i++)
                    {
                        totalAmount += r.AmountList[i].FromAtomicUnits();
                        totalFee    += r.FeeList[i].FromAtomicUnits();
                        txHashList  += $"{r.TxHashList[i]}\r\n";
                    }

                    Sender.PrivateReply(msg, $"{totalAmount} xnv was sent with a fee of {totalFee} xnv in {numTxs} transactions\r\n{txHashList}").Wait();
                },
                                   (RequestError e) =>
                {
                    Sender.PrivateReply(msg, "Oof. No good. You are going to have to try again later.").Wait();
                },
                                   cfg.WalletHost, cfg.UserWalletPort).RunAsync();
            }
        }
Beispiel #9
0
        public async Task Process(SocketUserMessage msg)
        {
            try{
                await commandLock.WaitAsync();
            } catch { return; }

            try
            {
                FusionBotConfig cfg = ((FusionBotConfig)Globals.Bot.Config);

                if (!cfg.UserWalletCache.ContainsKey(msg.Author.Id))
                {
                    await AccountHelper.CreateNewAccount(msg);
                }
                else
                {
                    int amount = 0;
                    if (!AccountHelper.ParseIntFromMessage(msg, out amount) || amount == 0)
                    {
                        await Sender.PublicReply(msg, "Oof. No good. You didn't say how many tickets you want.");

                        return;
                    }

                    double playerBalance = 0;

                    //get balance of player wallet
                    await new GetBalance(new GetBalanceRequestData {
                        AccountIndex = cfg.UserWalletCache[msg.Author.Id].Item1
                    }, (GetBalanceResponseData result) => {
                        playerBalance = result.UnlockedBalance.FromAtomicUnits() - 0.1;
                    }, (RequestError e) => {
                        Sender.PrivateReply(msg, "Oof. No good. You are going to have to try again later.").Wait();
                    }, cfg.WalletHost, cfg.UserWalletPort).RunAsync();

                    //if you can't afford all you have asked for, then you only get what you can afford
                    amount = Math.Min((int)(playerBalance / LotteryManager.CurrentGame.Parameters.TicketCost), amount);

                    await LotteryManager.CurrentGame.AllocateTickets(msg, amount);
                }
            }
            finally
            {
                commandLock.Release();
            }
        }
Beispiel #10
0
        public async Task Process(SocketUserMessage msg)
        {
            FusionBotConfig cfg = ((FusionBotConfig)Globals.Bot.Config);

            if (!cfg.UserWalletCache.ContainsKey(msg.Author.Id))
            {
                await AccountHelper.CreateNewAccount(msg);
            }
            else
            {
                double amount;
                if (!AccountHelper.ParseDoubleFromMessage(msg, out amount))
                {
                    await Sender.PrivateReply(msg, "Oof. No good. You didn't say how much you want to tip.");

                    return;
                }

                uint accountIndex = cfg.UserWalletCache[msg.Author.Id].Item1;

                foreach (var m in msg.MentionedUsers)
                {
                    if (cfg.UserWalletCache.ContainsKey(m.Id))
                    {
                        await SendToUser(msg, m, accountIndex, amount.ToAtomicUnits());
                    }
                    else
                    {
                        string address = await AccountHelper.CreateNewAccount(m);

                        if (!string.IsNullOrEmpty(address))
                        {
                            await Sender.PrivateReply(msg, $"{m.Mention} does not have a wallet. They cannot take your tip.");

                            await Sender.SendPrivateMessage(Globals.Client.GetUser(m.Id), $"{msg.Author.Mention} tried to send you {amount} xnv, but you don't have a wallet");
                        }
                        else
                        {
                            await SendToUser(msg, m, accountIndex, amount.ToAtomicUnits());
                        }
                    }
                }
            }
        }
Beispiel #11
0
        public async Task Process(SocketUserMessage msg)
        {
            FusionBotConfig cfg = ((FusionBotConfig)Globals.Bot.Config);

            if (!cfg.UserWalletCache.ContainsKey(msg.Author.Id))
            {
                await AccountHelper.CreateNewAccount(msg);
            }
            else
            {
                double betAmount;
                if (!AccountHelper.ParseDoubleFromMessage(msg, out betAmount))
                {
                    await Sender.PublicReply(msg, "Oof. No good. You didn't say how much you want to bet.");

                    return;
                }

                ulong totalAmount = betAmount.ToAtomicUnits() + (0.1d).ToAtomicUnits();

                //both parties must have the amount + 0.1xnv to cover potential fees

                uint   playerAccountIndex = cfg.UserWalletCache[msg.Author.Id].Item1;
                string playerAddress      = cfg.UserWalletCache[msg.Author.Id].Item2;
                ulong  playerBalance      = 0;

                string fusionAddress = cfg.UserWalletCache[cfg.BotId].Item2;
                ulong  fusionBalance = 0;

                //get balance of player wallet
                await new GetBalance(new GetBalanceRequestData {
                    AccountIndex = cfg.UserWalletCache[msg.Author.Id].Item1
                }, (GetBalanceResponseData result) => {
                    playerBalance = result.UnlockedBalance;
                }, (RequestError e) => {
                    Sender.PrivateReply(msg, "Oof. No good. You are going to have to try again later.").Wait();
                }, cfg.WalletHost, cfg.UserWalletPort).RunAsync();

                //get balance of fusion wallet
                await new GetBalance(new GetBalanceRequestData {
                    AccountIndex = cfg.UserWalletCache[cfg.BotId].Item1
                }, (GetBalanceResponseData result) => {
                    fusionBalance = result.UnlockedBalance;
                }, (RequestError e) => {
                    Sender.PrivateReply(msg, "Oof. No good. You are going to have to try again later.").Wait();
                }, cfg.WalletHost, cfg.UserWalletPort).RunAsync();

                if (playerBalance < totalAmount)
                {
                    await Sender.PublicReply(msg, "You ain't got enough cash. Maybe you need gamblers anonymous? :thinking:");

                    return;
                }

                if (fusionBalance < totalAmount)
                {
                    await Sender.PublicReply(msg, "Hold on high roller! I can't cover that :whale:");

                    return;
                }

                double d = MathHelper.Random.NextDouble();

                if (d > 0.5d) //payout
                {
                    RequestError err = await AccountHelper.PayUser(betAmount, cfg.BotId, msg.Author.Id);
                    await HandlePayoutResult(msg, true, err);
                }
                else //take it
                {
                    RequestError err = await AccountHelper.PayUser(betAmount, msg.Author.Id, cfg.BotId);
                    await HandlePayoutResult(msg, false, err);
                }
            }
        }
Beispiel #12
0
        public async Task Process(SocketUserMessage msg)
        {
            FusionBotConfig                 cfg       = ((FusionBotConfig)Globals.Bot.Config);
            GetAccountsResponseData         balances  = null;
            List <GetTransfersResponseData> transfers = new List <GetTransfersResponseData>();

            await new GetAccounts(null, (GetAccountsResponseData result) =>
            {
                balances = result;
            }, null, cfg.WalletHost, cfg.DonationWalletPort).RunAsync();

            if (balances == null)
            {
                await DiscordResponse.Reply(msg, text : "Sorry. Couldn't retrieve the donation account balances...");

                return;
            }

            foreach (var a in cfg.AccountJson.Accounts)
            {
                if (!a.Display)
                {
                    transfers.Add(null);
                    continue;
                }

                await new GetTransfers(new GetTransfersRequestData
                {
                    AccountIndex = (uint)a.Index
                }, (GetTransfersResponseData result) =>
                {
                    transfers.Add(result);
                }, null, cfg.WalletHost, cfg.DonationWalletPort).RunAsync();
            }

            if (cfg.AccountJson.Accounts.Length != transfers.Count)
            {
                await DiscordResponse.Reply(msg, text : "Sorry. Couldn't retrieve the donation account balances...");

                return;
            }

            EmbedBuilder eb = new EmbedBuilder()
                              .WithAuthor("Donation Account Balances", Globals.Client.CurrentUser.GetAvatarUrl())
                              .WithDescription("These are the balances of all the donation accounts")
                              .WithColor(Color.Red)
                              .WithThumbnailUrl(Globals.Client.CurrentUser.GetAvatarUrl());

            for (int i = 0; i < cfg.AccountJson.Accounts.Length; i++)
            {
                var a = cfg.AccountJson[i];

                if (!a.Display)
                {
                    continue;
                }

                var bb = balances.Accounts[i].UnlockedBalance;
                var tt = transfers[i];

                StringBuilder sb = new StringBuilder();

                foreach (var t in tt.Incoming.OrderByDescending(x => x.Height).Take(5))
                {
                    ulong s, r;
                    IdEncrypter.Decrypt(t.PaymentId, out s, out r);
                    sb.AppendLine($"{s.ToMention()}: {t.Amount.FromAtomicUnits()}");
                }

                sb.AppendLine("\u200b");

                ulong outTotal = 0;
                foreach (var o in tt.Outgoing)
                {
                    outTotal += o.Amount;
                }

                eb.AddField($"{a.Name}: {bb.FromAtomicUnits()} XNV ({outTotal.FromAtomicUnits()} out)", sb.ToString());
            }

            await DiscordResponse.Reply(msg, embed : eb.Build());
        }
Beispiel #13
0
        public async Task AllocateTickets(SocketUserMessage msg, int numRequested)
        {
            if (filled)
            {
                await Sender.PublicReply(msg, "Oof. Looks like you missed out on this round.");

                return;
            }

            List <int> unAllocated = new List <int>();

            for (int i = 0; i < numbers.Length; i++)
            {
                if (numbers[i] == 0)
                {
                    unAllocated.Add(i);
                }
            }

            //if we have requested more than are available, we need to fix that
            int r = Math.Min(numRequested, unAllocated.Count);

            int[] allocatedNumbers = new int[r];

            FusionBotConfig cfg = ((FusionBotConfig)Globals.Bot.Config);
            RequestError    err = await AccountHelper.PayUser(r *LotteryManager.CurrentGame.Parameters.TicketCost, msg.Author.Id, cfg.BotId);

            if (err != null)
            {
                await Sender.PublicReply(msg, $"{msg.Author.Mention} There was an error paying for your tickets.");

                return;
            }

            for (int i = 0; i < r; i++)
            {
                int x = MathHelper.Random.NextInt(0, unAllocated.Count);
                numbers[unAllocated[x]] = msg.Author.Id;
                allocatedNumbers[i]     = unAllocated[x];
                unAllocated.RemoveAt(x);
            }

            if (allocatedNumbers.Length > 0)
            {
                string s = string.Empty;
                for (int i = 0; i < allocatedNumbers.Length; i++)
                {
                    s += $"{allocatedNumbers[i]} ";
                }

                s = s.TrimEnd();

                await Sender.PublicReply(msg, $"{msg.Author.Mention} Your lucky numbers are {s}");

                //if we have allocated numbers here, we need to save this game
                //then we can persist after a restart
                new ObjectSerializer().Serialize(this, Path.Combine(Environment.CurrentDirectory, "lottery.xml"));
            }
            else
            {
                await Sender.PublicReply(msg, $"{msg.Author.Mention} I was unable to allocate you any numbers in this draw.");
            }

            if (unAllocated.Count == 0)
            {
                filled = true;
                await Sender.PublicReply(msg, $"All tickets are sold. Drawing the lottery!");
                await Draw();
            }
        }