async def work(self, ctx: Context):
        '''
        Earn your money the honest way! You can get between 50 and 300 dunk dollars working! 
        You can only work once every 30 minutes.
        '''
        guild_data = economy_collection.find_one({"_id": ctx.message.guild.id})

        members_data = guild_data['members']

        for member in members_data:
            if member['id'] == ctx.message.author.id:
                amount = random.randint(50, 300)
                member['money'] += amount

                break

            else:
                pass

        economy_collection.find_one_and_update(
            {"_id": ctx.message.guild.id}, {"$set": {
                "members": members_data
            }})

        embed = discord.Embed(title=":office: Job",
                              description=f"You earned {amount} coins!",
                              color=discord.Color.blurple())

        await ctx.send(embed=embed)
    async def balance(self, ctx: Context, user: discord.Member = None):
        '''
        Check your account balance.
        '''
        if user == None:
            user = ctx.message.author

        members_data = economy_collection.find_one(
            {"_id": ctx.message.guild.id})['members']

        for member in members_data:
            if member['id'] == user.id:
                embed = discord.Embed(
                    title=":bank: Bank of Dunkville",
                    description=
                    f"Bank statement of {user.name}#{user.discriminator}",
                    color=discord.Color.blurple())

                embed.add_field(name=":moneybag: Cash",
                                value=f"`{member['money']}$`")

                embed.add_field(name=":bank: Account",
                                value=f"`{member['bank']}$`")

                embed.set_footer(
                    text=f"Requested by {user.name}#{user.discriminator}")

                await ctx.send(embed=embed)

                break

            else:
                pass
Esempio n. 3
0
def setup_database(client: Bot):
    for guild in client.guilds:
        if not economy_collection.find_one({"_id": guild.id}):
            members = []

            for member in guild.members:
                members.append({"id": member.id, "money": 0, "bank": 0})

            economy_collection.insert_one({
                "_id": guild.id,
                "name": guild.name,
                "members": members
            })

        else:
            pass

        if not settings_collection.find_one({"_id": guild.id}):
            settings_collection.insert_one({
                "_id": guild.id,
                "name": guild.name,
                "settings": {}
            })

        else:
            pass
    async def withdraw(self, ctx: Context, amount: int):
        '''
        Withdraw money to spend it on items!
        You can use `all` as the amount to withdraw all of your cash from the bank.
        '''
        members_data = economy_collection.find_one({"_id":
                                                    ctx.guild.id})['members']

        final = None

        for member in members_data:
            if member['id'] == ctx.message.author.id:
                final = member

                if amount == 'all':
                    amount = member['bank']

                    member['bank'] -= amount
                    member['money'] += amount

                    break

                elif int(amount) <= member['bank']:
                    member['money'] += int(amount)
                    member['bank'] -= int(amount)

                    break

                else:
                    amount = member['bankk']

                    member['money'] += amount
                    member['bank'] -= amount

                    break

            else:
                pass

        economy_collection.update_one({"_id": ctx.guild.id},
                                      {"$set": {
                                          "members": members_data
                                      }})

        embed = discord.Embed(
            title=":bank: Bank of Dunkville",
            description=
            f"Succesfully deposited {amount}$ in your bank account.",
            color=discord.Color.blurple())

        embed.add_field(name=":moneybag: Cash", value=f"`{final['money']}$`")

        embed.add_field(name=":bank: Account", value=f"`{final['bank']}$`")

        await ctx.send(embed=embed)
Esempio n. 5
0
    async def on_member_remove(self, member: discord.Member):
        members_data = economy_collection.find_one({"_id": member.guild.id
                                                    })['members']

        i = 0

        for user in members_data:
            if user['id'] == member.id:
                del members_data[i]
                break

            else:
                pass

            i += 1

        economy_collection.find_one_and_update(
            {"_id": member.guild.id}, {"$set": {
                "members": members_data
            }})

        settings = settings_collection.find_one({"_id":
                                                 member.guild.id})['settings']

        if 'welcome_channel' in settings.keys():
            welcome_channel = get(member.guild.text_channels,
                                  id=settings['welcome_channel'])

            if 'leave_message' in settings.keys():
                leave_message = settings['leave_message']

                if "{ mention }" in leave_message:
                    leave_message.replace("{ mention }", member.mention)

                embed = discord.Embed(title=f"**{member.guild.name}**",
                                      description=f"{leave_message}",
                                      color=discord.Color.dark_purple())

                await welcome_channel.send(embed=embed)

            else:
                embed = discord.Embed(
                    title=f"**{member.guild.name}**",
                    description=
                    f"Bye {member.mention}! We're sorry to see you go :(",
                    color=discord.Color.dark_purple())

                await welcome_channel.send(embed=embed)

        else:
            pass
Esempio n. 6
0
    async def on_member_join(self, member: discord.Member):
        members_data = economy_collection.find_one({"_id": member.guild.id
                                                    })['members']

        members_data.append({"id": member.id, "money": 0, "bank": 0})

        economy_collection.find_one_and_update(
            {"_id": member.guild.id}, {"$set": {
                "members": members_data
            }})

        settings = settings_collection.find_one({"_id":
                                                 member.guild.id})['settings']

        if 'welcome_channel' in settings.keys():
            welcome_channel = get(member.guild.text_channels,
                                  id=settings['welcome_channel'])

            if 'join_message' in settings.keys():
                join_message = settings['join_message']

                if "{ mention }" in join_message:
                    join_message.replace("{ mention }", member.mention)

                embed = discord.Embed(title=f"**{member.guild.name}**",
                                      description=f"{join_message}",
                                      color=discord.Color.green())

                await welcome_channel.send(embed=embed)

            else:
                embed = discord.Embed(
                    title=f"**{member.guild.name}**",
                    description=
                    f"Welcome to {member.guild.name}! :partying_face:",
                    color=discord.Color.green())

                await welcome_channel.send(embed=embed)

        else:
            pass
    async def daily(self, ctx: Context):
        '''
        Collect your daily 500 dunk dollar bonus!
        '''
        members = economy_collection.find_one({"_id": ctx.guild.id})['members']

        for member in members:
            if member['id'] == ctx.author.id:
                member['money'] += 500

        embed = discord.Embed(
            title="**Daily bonus!**",
            description=
            ":white_check_mark: Successfully claimed your daily `500` dunk dollars bonus!",
            color=discord.Color.green())

        economy_collection.find_one_and_update({"_id": ctx.guild.id},
                                               {"$set": {
                                                   "members": members
                                               }})

        await ctx.send(embed=embed)
    async def rob(self, ctx: Context, user: discord.Member):
        '''
        Take a risk and mug someone... You can lose a lot of money if you get caught... But you can also *win* a lot of money if you get away with it!
        You can only rob someone every 3 hours.
        Rewards are between 300 and 1000 dunk dollars. Fines are between 100 and 200 dunk dollars.
        '''
        members_data = economy_collection.find_one({"_id":
                                                    ctx.guild.id})['members']

        robber = ctx.author
        victim = user

        success = random.random() * 100

        amount = random.randint(300, 1000)
        fine = random.randint(100, 200)

        if success >= 30.0:
            for member in members_data:
                if member['id'] == robber.id:
                    if member['money'] < fine:
                        member['money'] = 0

                    else:
                        member['money'] -= fine

                elif member['id'] == victim.id:
                    member['money'] += fine * 2

                else:
                    pass

            embed = discord.Embed(
                title="Busted!",
                description=
                f"You tried robbing {victim.mention} but you got caught and you lost {amount} coins!",
                color=discord.Color.red())

            await ctx.send(embed=embed)

        else:
            for member in members_data:
                if member['id'] == robber.id:
                    member['money'] += amount

                elif member['id'] == victim.id:
                    if member['money'] < (amount / 2):
                        member['money'] = 0

                    else:
                        member['money'] -= (amount / 2)
                else:
                    pass

            embed = discord.Embed(
                title="Success!",
                description=
                f"You managed to get away with robbing {victim.mention} and earned {amount}!",
                color=discord.Color.green())

            await ctx.send(embed=embed)

        economy_collection.update_one({"_id": ctx.guild.id},
                                      {"$set": {
                                          "members": members_data
                                      }})