Exemple #1
0
        public async Task WithdrawAsync(string Amount, [Remainder] string Remainder = "")
        {
            // Delete original message
            try { await Context.Message.DeleteAsync(); }
            catch { }

            // Check if user exists in user table
            if (!TrtlBotSharp.CheckUserExists(Context.Message.Author.Id))
            {
                await Context.Message.Author.SendMessageAsync(string.Format("You must register a wallet before you can withdraw! Use {0}help if you need any help.", TrtlBotSharp.botPrefix));

                return;
            }

            // Check that amount is over the minimum fee
            else if (Convert.ToDecimal(Amount) < TrtlBotSharp.Minimum)//TrtlBotSharp.Fee)
            {
                await ReplyAsync(string.Format("Amount must be at least {0:N} {1}", TrtlBotSharp.Minimum /*Fee*/, TrtlBotSharp.coinSymbol));

                return;
            }

            // Check if user has enough balance
            else if (TrtlBotSharp.GetBalance(Context.Message.Author.Id) < Convert.ToDecimal(Amount) + TrtlBotSharp.tipFee)
            {
                await Context.Message.Author.SendMessageAsync(string.Format("Your balance is too low! Amount + Fee = **{0:N}** {1}",
                                                                            Convert.ToDecimal(Amount) + TrtlBotSharp.tipFee, TrtlBotSharp.coinSymbol));

                await Context.Message.AddReactionAsync(new Emoji(TrtlBotSharp.tipLowBalanceReact));
            }

            // Send withdrawal
            else if (TrtlBotSharp.Tip(Context.Message.Author.Id, TrtlBotSharp.GetAddress(Context.Message.Author.Id), Convert.ToDecimal(Amount)))
            {
                // Send success react
                await Context.Message.AddReactionAsync(new Emoji(TrtlBotSharp.tipSuccessReact));
            }
        }
Exemple #2
0
        public async Task TipAsync(string Amount, [Remainder] string Remainder = "")
        {
            // Check if user exists in user table
            if (!TrtlBotSharp.CheckUserExists(Context.Message.Author.Id))
            {
                await Context.Message.Author.SendMessageAsync(string.Format("You must register a wallet before you can tip! Use {0}help if you need any help.", TrtlBotSharp.botPrefix));

                return;
            }

            // Check that amount is over the minimum fee
            if (Convert.ToDecimal(Amount) < TrtlBotSharp.Minimum)//TrtlBotSharp.Fee)
            {
                await ReplyAsync(string.Format("Amount must be at least {0:N} {1}", TrtlBotSharp.Minimum /*Fee*/, TrtlBotSharp.coinSymbol));

                return;
            }

            // Check if an address is specified instead of mentioned users
            string Address = "";

            if (Remainder.StartsWith(TrtlBotSharp.coinAddressPrefix) && Remainder.Length == TrtlBotSharp.coinAddressLength)
            {
                Address = Remainder.Substring(0, 97);
            }

            if (TrtlBotSharp.logLevel >= 3)
            {
                Console.Write($"The wallet ADDRESS is = *{Address}*\n");
            }

            // Check that there is at least one mentioned user
            if (Address == "" && Context.Message.MentionedUsers.Count < 1)
            {
                return;
            }

            // Remove duplicate mentions
            List <ulong> Users = new List <ulong>();

            foreach (SocketUser MentionedUser in Context.Message.MentionedUsers)
            {
                Users.Add(MentionedUser.Id);
                if (TrtlBotSharp.logLevel >= 3)
                {
                    Console.Write($"MentionedUserID = *{MentionedUser.Id}*\n");
                }
            }

            Users = Users.Distinct().ToList();

            // Create a list of users that have wallets
            List <ulong> TippableUsers = new List <ulong>();

            foreach (ulong Id in Users)
            {
                if (TrtlBotSharp.CheckUserExists(Id) && Id != Context.Message.Author.Id)
                {
                    TippableUsers.Add(Id);
                }
                if (TrtlBotSharp.logLevel >= 3)
                {
                    Console.Write($"CheckUserExists ID  = *{Id}*\n");
                    Console.Write($"TippableUsers Count = {TippableUsers.Count}\n");
                    Console.Write($"Tip Amount          = {Amount}\n");
                }
            }

            if (TrtlBotSharp.logLevel >= 3)
            {
                Console.Write($"Tip Fee = {TrtlBotSharp.tipFee}\n");
            }

            // Check that user has enough balance for the tip
            if (Address == "" && TrtlBotSharp.GetBalance(Context.Message.Author.Id) < ((Convert.ToDecimal(Amount) * TippableUsers.Count) + TrtlBotSharp.tipFee))
            {
                await Context.Message.Author.SendMessageAsync(string.Format("1-Your balance is too low! Amount + Fee = **{0:N}** {1}",
                                                                            ((Convert.ToDecimal(Amount) * TippableUsers.Count) + TrtlBotSharp.tipFee), TrtlBotSharp.coinSymbol));

                await Context.Message.AddReactionAsync(new Emoji(TrtlBotSharp.tipLowBalanceReact));
            }
            else if (TrtlBotSharp.GetBalance(Context.Message.Author.Id) < Convert.ToDecimal(Amount) + TrtlBotSharp.tipFee)
            {
                await Context.Message.Author.SendMessageAsync(string.Format("2-Your balance is too low! Amount + Fee = **{0:N}** {1}",
                                                                            Convert.ToDecimal(Amount) + TrtlBotSharp.tipFee, TrtlBotSharp.coinSymbol));

                await Context.Message.AddReactionAsync(new Emoji(TrtlBotSharp.tipLowBalanceReact));
            }

            // Tip has required arguments
            else
            {
                if (Address == "")
                {
                    // Send a failed react if a user isn't found
                    bool FailReactAdded = false;
                    foreach (ulong User in Users)
                    {
                        if (User != Context.Message.Author.Id && !TippableUsers.Contains(User))
                        {
                            if (!FailReactAdded)
                            {
                                await Context.Message.AddReactionAsync(new Emoji(TrtlBotSharp.tipFailedReact));

                                FailReactAdded = true;
                            }

                            try {
                                // Begin building a response
                                var Response = new EmbedBuilder();
                                Response.WithTitle(string.Format("{0} wants to tip you!", Context.Message.Author.Username));
                                Response.Description = string.Format("Register your wallet with with `{0}registerwallet <your {1} address>` " +
                                                                     "to get started!\nTo create a wallet head to https://turtlecoin.lol/wallet/\nExtra Help: http://docs.turtlecoin.lol/",
                                                                     TrtlBotSharp.botPrefix, TrtlBotSharp.coinSymbol);

                                // Send reply
                                await Context.Client.GetUser(User).SendMessageAsync("", false, Response);
                            }
                            catch { }
                        }
                    }

                    // Check that there is at least one user with a registered wallet
                    if (TippableUsers.Count > 0 && TrtlBotSharp.Tip(Context.Message.Author.Id, TippableUsers, Convert.ToDecimal(Amount), Context.Message))
                    {
                        // Send success react
                        await Context.Message.AddReactionAsync(new Emoji(TrtlBotSharp.tipSuccessReact));
                    }
                }
                else if (TrtlBotSharp.Tip(Context.Message.Author.Id, Address, Convert.ToDecimal(Amount)))
                {
                    // Send success react
                    await Context.Message.AddReactionAsync(new Emoji(TrtlBotSharp.tipSuccessReact));
                }
            }
        }