Beispiel #1
0
def set_money(guild, amount, wallet):
    #server_members = list(map(lambda member:member.id, guild.members))
    #s#erver_roles = list(map(lambda role: role.id, guild.roles))
    if ("-" in amount):
        amount_array = amount.split("-")
        print(amount.split("-"))
        amount = amount_array[0]
        currency = amount_array[1]
    if 'currency' in locals():
        if (not methods.valid_item(currency)):
            return (False, "invaid item name")
    if (not amount.isdigit()):
        return (False, "incorrect ammount")
    guild_collection = db[str(guild.id)]
    to_wallet = methods.get_wallet(guild, wallet)
    if (not to_wallet[0]):
        return to_wallet
    found_wallet = methods.find_create(to_wallet[1].id, guild)
    if 'currency' in locals():
        guild_collection.update_one(
            {"id": to_wallet[1].id},
            {"$set": {
                f'balance-{currency}': int(amount)
            }})
        return (True, f'balance was set to {amount}')
    guild_collection.update_one({"id": to_wallet[1].id},
                                {"$set": {
                                    "balance": int(amount)
                                }})
    return (True, f'balance was set to {amount}')
def message_money(person, guild):
    wallet = methods.find_create(person.id, guild)
    server_config = methods.get_server_config(guild.id)
    message_cooldown = config[""]
# if "message-cooldown" in wallet:

#      if
Beispiel #3
0
 async def convert(self, ctx, wallet):
     if wallet is None:
         wallet = ctx.author.mention
     get_wallet_result = methods.get_wallet(ctx.guild, wallet)
     if not get_wallet_result[0]:
         raise BadArgument(f'person {wallet} does not exist in this guild')
     db_wallet = methods.find_create(get_wallet_result[1].id, ctx.guild)
     #print("db_wallet:", db_wallet)
     return db_wallet
Beispiel #4
0
def print_money(person, guild, wallet, amount):
    currency = ""
    if "-" in amount:
        currency = f'-{amount.split("-")[1]}'
        amount = amount.split("-")[0]

        if not methods.valid_item(currency[1:]):
            return (False, "invalid item name")
    try:
        amount = int(amount)
    except:
        return (False, "invalid amount")

    guild_collection = db[str(guild.id)]
    wallet_id = methods.get_wallet(guild, wallet)
    if not wallet_id[0]:
        return (False, "invalid wallet name")
    can_print = False
    if person.guild_permissions.administrator:
        can_print = True
    account_of_printing = methods.find_create(wallet_id[1].id, guild)
    if account_of_printing is None:
        c_result = create(guild, wallet)
        if not c_result[0]:
            return (False, c_result[1])
        account_of_printing = c_result[2]
        #return (False,"can't find doesn't exist")
    if "permissions" in account_of_printing:
        if "print" in account_of_printing["permissions"]:
            if person.id in account_of_printing["permissions"]["print"][
                    "true"]:
                can_print = True
            for role in person.roles:
                if role.id in account_of_printing["permissions"]["print"][
                        "true"]:
                    can_print = True
        if currency != "":
            if f'print{currency}' in account_of_printing["permissions"]:
                if person.id in account_of_printing["permissions"][
                        f'print{currency}']["true"]:
                    can_print = True
                for role in person.roles:
                    if role.id in account_of_printing["permissions"][
                            f'print{currency}']["true"]:
                        can_print = True
    if "printer" in person.roles:
        can_print = True
    if not can_print:
        return (False, "you do not have permission to print")
    guild_collection.update_one({"id": account_of_printing["id"]},
                                {"$inc": {
                                    f'balance{currency}': amount
                                }})
    return (True, "transfer successful")
Beispiel #5
0
    async def graph(self, ctx, wallet):
        result = methods.get_wallet(ctx.guild, wallet)
        if (result[0]):
            print(result)
            found_wallet = methods.find_create(result[1].id, ctx.guild)
            if "record" in found_wallet:
                fig = plt.figure(figsize=(10, 5))
                X1 = list(found_wallet["record"].keys())
                Y1 = list(found_wallet["record"].values())

                plt.plot(X1, Y1, label="plot 1")
                fig.savefig('fig.jpg', bbox_inches='tight', dpi=150)
                return await ctx.send(file=discord.File('fig.jpg'))
                os.remove("fig.jpg")
            else:
                return await ctx.send(
                    embed=simple_embed(False, "can't find any stats"))
        else:
            await ctx.send(embed=simple_embed(False, "error"))
    async def work(self, ctx):
        guild = ctx.guild
        person = ctx.author
        wallet = methods.find_create(person.id, guild)
        cooldown = config["work-cooldown"]
        guild_collection = db[str(guild.id)]

        server_config = guild_collection.find_one({
            "type": "server",
            "id": guild.id
        })
        if server_config is not None:
            if "work-cooldown" in server_config:
                cooldown = server_config["work-cooldown"]
        if "cooldown-work" in wallet:
            print(time.time(), wallet["cooldown-work"],
                  time.time() - wallet["cooldown-work"], cooldown)
            if time.time() - wallet["cooldown-work"] < cooldown:
                return await ctx.send(embed=simple_embed(
                    False,
                    f'wait to work. You must wait {methods.seconds_to_time(cooldown- time.time()+wallet["cooldown-work"])} to work again'
                ))
        payout = [{"name": "Bot default", "amount": config["work-payoff"]}]
        if server_config is not None:
            if "work-payoff" in server_config:
                payout[0] = {
                    "name": "server default",
                    "amount": server_config["work-payoff"]
                }
            if "work-conditional" in server_config:
                payout += server_config["work-conditional"]
        parsed_message = ""
        for index in payout:
            if "condition" in index:
                print(index["condition"])
                if person.id not in methods.whois(
                        index["condition"].split(" "), guild):
                    print(
                        person.id,
                        methods.whois(index["condition"].split(" "),
                                      guild), person.id
                        not in methods.whois(index["condition"].split(" "),
                                             guild))
                    continue
            amount = index["amount"]
            if "-" in str(amount):
                amount = str(amount)
                currency = f'-{amount.split("-")[1]}'
                amount = int(amount.split("-")[0])
            else:
                currency = ""
                amount = int(amount)
            guild_collection.update_one(
                {"id": person.id}, {"$inc": {
                    f'balance{currency}': amount
                }})
            parsed_message += f'\n {index["amount"]} from {index["name"]}'

        guild_collection.update_one({"id": person.id},
                                    {"$set": {
                                        f'cooldown-work': time.time()
                                    }})
        lines = open('data/jobs.txt').read().splitlines()
        job = random.choice(lines)
        return await ctx.send(embed=simple_embed(
            True, f'You worked as {job} and earned {parsed_message}'))
Beispiel #7
0
 async def fulfill_trade(self, ctx, wallet, message):
     guild = ctx.guild
     person = ctx.author
     found_wallet = methods.get_wallet(guild, wallet)
     if not found_wallet[0]:
         return await ctx.send(embed=simple_embed(False, "cant find wallet")
                               )
     if not methods.can_access_wallet(guild, person.id, wallet):
         return await ctx.send(
             embed=simple_embed(False, "cannot access wallet"))
     try:
         message = int(message)
     except:
         return await ctx.send(embed=simple_embed(False, "invalid number"))
     guild_collection = db[str(guild.id)]
     found_offer = guild_collection.find_one({
         "type": "trade",
         "message_id": message
     })
     if found_offer is None:
         return await ctx.send(embed=simple_embed(False, "can't find offer")
                               )
     if "uses" in found_offer:
         if found_offer["uses"] <= 0:
             guild_collection.delete_one(
                 {"message_id": found_offer["message_id"]})
             return await ctx.send(
                 embed=simple_embed(False, "offer has been used up"))
     if "offer_time" in found_offer:
         if time.time() > found_offer["offer_time"]:
             guild_collection.delete_one(
                 {"message_id": found_offer["message_id"]})
             return await ctx.send(
                 embed=simple_embed(False, "offer has run out of time"))
     if "people_restrictions" in found_offer:
         if person.id not in methods.whois(
                 found_offer["people_restrictions"], guild):
             return await ctx.send(embed=simple_embed(
                 False,
                 "you cannot accept this offer because a restriction has bee"
             ))
     receiver = methods.find_create(found_wallet[1].id, ctx.guild)
     if f'balance{found_offer["cost_currency"]}' not in receiver:
         return await ctx.send(
             embed=simple_embed(False, "you have no money"))
     if receiver[f'balance{found_offer["cost_currency"]}'] < found_offer[
             "cost_amount"]:
         return await ctx.send(
             embed=simple_embed(False, "you don't have enough money"))
     sender = guild_collection.find_one({"id": found_offer["person"]})
     if "wallet" in found_offer:
         if f'balance{found_offer["offer_currency"]}' not in sender:
             guild_collection.delete_one(
                 {"message_id": found_offer["message_id"]})
             return await ctx.send(embed=simple_embed(
                 False,
                 "offer deleted, person does not have enough for trade"))
         if sender[f'balance{found_offer["offer_currency"]}'] < found_offer[
                 "offer_amount"]:
             guild_collection.delete_one(
                 {"message_id": found_offer["message_id"]})
             return await ctx.send(embed=simple_embed(
                 False,
                 "offer deleted, person does not have enough for trade"))
     guild_collection.update_one({"id": receiver["id"]}, {
         "$inc": {
             f'balance{found_offer["offer_currency"]}':
             -int(found_offer["offer_amount"])
         }
     })
     guild_collection.update_one({"id": receiver["id"]}, {
         "$inc": {
             f'balance{found_offer["cost_currency"]}':
             int(found_offer["cost_amount"])
         }
     })
     if " wallet" in found_offer:
         guild_collection.update_one({"id": sender["id"]}, {
             "$inc": {
                 f'balance{found_offer["offer_currency"]}':
                 int(found_offer["offer_amount"])
             }
         })
         guild_collection.update_one({"id": sender["id"]}, {
             "$inc": {
                 f'balance{found_offer["cost_currency"]}':
                 -int(found_offer["cost_amount"])
             }
         })
     if re.match(r'<@&?\d{18}>', found_offer["offer_currency"]) is not None:
         try:
             loop = asyncio.get_event_loop()
             id_role = re.findall(r'\d{18}',
                                  found_offer["offer_currency"])[0]
             print(id_role)
             id_role = int(id_role)
             role = discord.utils.get(guild.roles, id=id_role)
             print(role)
             loop.create_task(person.add_roles(role))
         except:
             return await ctx.send(
                 embed=simple_embed(False, "bad permissions"))
     if "uses" in found_offer:
         guild_collection.update_one(
             {"message_id": found_offer["message_id"]},
             {"$inc": {
                 "uses": -1
             }})
     return await ctx.send(embed=simple_embed(True, "success"))