예제 #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 (!PlenteumBot.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.", PlenteumBot.botPrefix));

                return;
            }

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

                return;
            }

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

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

            // Send withdrawal
            else if (PlenteumBot.Tip(Context.Message.Author.Id, PlenteumBot.GetAddress(Context.Message.Author.Id), Convert.ToDecimal(Amount)))
            {
                // Send success react
                await Context.Message.AddReactionAsync(new Emoji(PlenteumBot.tipSuccessReact));
            }
        }
예제 #2
0
        public async Task BalanceAsync([Remainder] string Remainder = "")
        {
            // Delete original message
            try { await Context.Message.DeleteAsync(); }
            catch { }

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

            // Send reply with balance
            else
            {
                // Get balance
                decimal Balance = PlenteumBot.GetBalance(Context.Message.Author.Id);

                // Send reply
                await Context.Message.Author.SendMessageAsync(string.Format("You have **{0:N}** {1} in your tip jar", Balance, PlenteumBot.coinSymbol));
            }
        }
예제 #3
0
        public async Task TipAsync(string Amount, [Remainder] string Remainder = "")
        {
            // Check if user exists in user table
            if (!PlenteumBot.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.", PlenteumBot.botPrefix));

                return;
            }

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

                return;
            }

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

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

            //
            List <ulong> Users = new List <ulong>();

            decimal tipAmount = 0;
            //check if "here" or "everyone" is mentioned
            bool multiUser   = false;
            bool hasEveryone = false;
            bool hasHere     = false;

            bool hasRoleMentions = false;

            if (Context.Message.MentionedRoles.Count > 0)
            {
                hasRoleMentions = true;
            }
            else
            {
                if (Context.Message.Tags.Count > 0)
                {
                    foreach (var tag in Context.Message.Tags)
                    {
                        if (tag.Type == TagType.RoleMention || tag.Type == TagType.HereMention || tag.Type == TagType.EveryoneMention)
                        {
                            hasRoleMentions = true;
                        }
                    }
                }
            }
            if (string.IsNullOrEmpty(Address) && hasRoleMentions)
            {
                //first ensure we have all members downloaded
                if (!Context.Guild.HasAllMembers)
                {
                    await Context.Guild.DownloadUsersAsync();
                }

                foreach (var tag in Context.Message.Tags)
                {
                    if (tag.Type == TagType.EveryoneMention)
                    {
                        //add each member to the tip
                        foreach (var user in Context.Guild.Users)
                        {
                            if (!Users.Contains(user.Id) && !user.IsBot && !user.IsWebhook) //only add if they not already in the list of users
                            {
                                Users.Add(user.Id);
                            }
                        }
                        hasEveryone = true;
                    }
                    else if (tag.Type == TagType.HereMention)
                    {
                        foreach (var user in Context.Guild.Users)
                        {
                            //only add if they not already in the list of users & are Online or Idle or AFK
                            if (!Users.Contains(user.Id) && !user.IsBot && !user.IsWebhook && (user.Status == UserStatus.Online || user.Status == UserStatus.Idle || user.Status == UserStatus.AFK))
                            {
                                Users.Add(user.Id);
                            }
                        }
                        hasHere = true;
                    }
                    else if (tag.Type == TagType.RoleMention)
                    {
                        foreach (var role in Context.Message.MentionedRoles)
                        {
                            foreach (var user in Context.Guild.Users)
                            {
                                //only add if they not already in the list of users & are in one of the mentioned roles
                                if (!Users.Contains(user.Id) && user.Roles.Contains(role) && !user.IsBot && !user.IsWebhook)
                                {
                                    Users.Add(user.Id);
                                }
                            }
                        }
                    }
                }

                //get users in Mentioned Roles if there is no "RoleMention" tag and the Users List is empty
                if (Context.Message.MentionedRoles.Count > 0 && Users.Count == 0)
                {
                    foreach (var role in Context.Message.MentionedRoles)
                    {
                        foreach (var user in Context.Guild.Users)
                        {
                            //only add if they not already in the list of users & are in one of the mentioned roles
                            if (!Users.Contains(user.Id) && user.Roles.Contains(role))
                            {
                                Users.Add(user.Id);
                            }
                        }
                    }
                }

                //check if everyone or here is mentioned by a tipper who is not allowed to mention @everyone or @here
                //first ensure we have all members downloaded
                if (Users.Count <= 0)
                {
                    if (!Context.Guild.HasAllMembers)
                    {
                        await Context.Guild.DownloadUsersAsync();
                    }

                    if (Remainder.ToLower().IndexOf("@everyone") > -1 && !hasEveryone)
                    {
                        //everyone was mentioned by a tipper who does not have permission to mention everyone
                        //so, discord will prevent notifying everyone, but the tip should still be sent
                        foreach (var user in Context.Guild.Users)
                        {
                            if (!Users.Contains(user.Id) && !user.IsBot && !user.IsWebhook) //only add if they not already in the list of users
                            {
                                Users.Add(user.Id);
                            }
                        }
                    }

                    if (Remainder.ToLower().IndexOf("@here") > -1 && !hasHere)
                    {
                        //everyone was mentioned by a tipper who does not have permission to mention @here
                        //so, discord will prevent notifying @here, but the tip should still be sent
                        foreach (var user in Context.Guild.Users)
                        {
                            //only add if they not already in the list of users & are Online or Idle or AFK
                            if (!Users.Contains(user.Id) && !user.IsBot && !user.IsWebhook && (user.Status == UserStatus.Online || user.Status == UserStatus.Idle || user.Status == UserStatus.AFK))
                            {
                                Users.Add(user.Id);
                            }
                        }
                    }
                }

                //check there are now users to tip
                if (Users.Count <= 0)
                {
                    await Context.Message.Author.SendMessageAsync(string.Format("There were no users found with the mentioned role!", PlenteumBot.botPrefix));

                    await Context.Message.AddReactionAsync(new Emoji(PlenteumBot.tipFailedReact));

                    return;
                }
                else
                {
                    //we're tipping users that do or don't have a wallet
                    multiUser = true;
                }
                //divide the tip Amount by the number of users
                tipAmount = Convert.ToDecimal(Amount) / Users.Count;

                //ensure round down and limit to two decimal places...
                tipAmount = Math.Floor(tipAmount * 100) / 100;
                //check that the splitAmount is LESS than or equal to the specified amount..
                if (tipAmount * Users.Count > Convert.ToDecimal(Amount))
                {
                    await Context.Message.Author.SendMessageAsync(string.Format("Something went wrong! The total tip amount is greater than the specified tip amount", PlenteumBot.botPrefix));

                    await Context.Message.AddReactionAsync(new Emoji(PlenteumBot.tipFailedReact));

                    return;
                }

                if (tipAmount < PlenteumBot.Minimum)
                {
                    await Context.Message.Author.SendMessageAsync(string.Format("The amount you've specified would result in the individual tip amounts being less than the minimum tip amount!", PlenteumBot.botPrefix));

                    await Context.Message.AddReactionAsync(new Emoji(PlenteumBot.tipFailedReact));

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

            // Remove duplicate mentions
            foreach (SocketUser MentionedUser in Context.Message.MentionedUsers)
            {
                Users.Add(MentionedUser.Id);
            }

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

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

            foreach (ulong Id in Users)
            {
                if (PlenteumBot.CheckUserExists(Id) && Id != Context.Message.Author.Id)
                {
                    TippableUsers.Add(Id);
                }
            }



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

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

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

            // Tip has required arguments
            else
            {
                if (Address == "")
                {
                    //if the splitAmount is > 0, tp that amount instead of the specified amount
                    if (tipAmount == 0)
                    {
                        tipAmount = Convert.ToDecimal(Amount);
                    }

                    // 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(PlenteumBot.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://wallet.plenteum.com/",
                                                                     PlenteumBot.botPrefix, PlenteumBot.coinSymbol);

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

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