コード例 #1
0
 async def whois(self, ctx, *condititons):
     people = methods.whois(condititons, ctx.guild)
     return_statement = ""
     symbol = "\n"
     if len(people)> 7:
         symbol = ","
     for index,person in enumerate(people):
         if len(return_statement) > 700:
             return_statement += f' and {len(people)-index} others'
             break
         return_statement = return_statement + f'<@{person}>{symbol}'
     if return_statement == "":
         return_statement = "(no people found)"
     embedVar = discord.Embed(title="Result", description=f'Found {len(people)} People', color=0x00ff00)
     embedVar.add_field(name="People", value=return_statement, inline=False)
     await ctx.send(embed=embedVar)
 async def set_balance_each(self, ctx, amount, *, condition):
     print("amount is", amount)
     print("condition is", condition)
     return_statement = ""
     successful_transfer = True
     people = methods.whois(condition.split(" "), ctx.guild)
     for person in people:
         wc = WalletConverter()
         person = await wc.convert(ctx, f'<@{person}>')
         send_result = await set_money(ctx.guild, person, amount)
         if send_result[0]:
             return_statement = return_statement + f'<@{person["id"]}> - success\n'
         else:
             return_statement = return_statement + f'<@{person["id"]}> - error: {send_result[1]}\n'
             successful_transfer = False
     if return_statement == "":
         return_statement = "(no people found)"
     return await ctx.channel.send(
         embed=simple_embed(successful_transfer, return_statement))
コード例 #3
0
 async def send_each(self, ctx, from_wallet:WalletConverter, amount, *conditions):
     people = methods.whois(conditions, ctx.guild)
     wc  = WalletConverter()
     return_statement = ""
     successful_transfer = True
     for person in people:
         send_result = await send(ctx.guild,ctx.author, from_wallet, await wc.convert(ctx,f'<@{person}>'), amount)
         print("send_result",send_result)
         if  send_result[0]:
             return_statement = return_statement + f'<@{person}> - success\n'
         else:
             return_statement = return_statement + f'<@{person}> - error: {send_result[1]}\n'
             successful_transfer = False
     if return_statement == "":
         return_statement = "(no people found)"
     if successful_transfer :
         embedVar = discord.Embed(title="Result", color=0x00ff00)
     else:
         embedVar = discord.Embed(title="Result", color=0xff0000)
     embedVar.add_field(name="People", value=return_statement, inline=False)
     return await ctx.send(embed=embedVar)
コード例 #4
0
    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}'))
コード例 #5
0
    async def on_message(self, message):
        if message.guild is None:
            await message.author.send(
                "I can only respond to messages in guilds")
            return
        message.content = message.content.replace("  ", " ")
        person_roles = list(map(lambda role: role.id, message.author.roles))
        server_members = list(
            map(lambda member: member.id, message.guild.members))
        server_roles = list(map(lambda role: role.id, message.guild.roles))
        person_id = message.author.id
        if (message.author.bot):
            return
        ##(guild, message,  person_roles,server_members,server_roles,person_id)
        trigger_msg = database.trigger_messages(message.guild, message,
                                                person_roles, server_members,
                                                server_roles,
                                                message.author.id)
        #print(trigger_msg)
        if trigger_msg is not None:
            for i in trigger_msg:
                if (i[1]):
                    if (not i[0]):
                        await message.channel.send(embed=embeds.simple_embed(
                            False,
                            f'<@!{i[2]}> your smart contract was annuled: {i[1]}'
                        ))
                    else:
                        await message.channel.send(embed=embeds.simple_embed(
                            True, f'a smart contract said: {i[1]}'))
        answer = database.answer_question(message.author, message.content,
                                          message.guild)
        if answer is not None:
            await message.channel.send(
                embed=embeds.simple_embed(answer[0], answer[1]))
        if (message.content.startswith("$")):
            if (message.content.startswith("$smart-contract")):
                if (message.content.count("```") == 2):
                    if (message.content.split("```")[0].count(" ") == 2):
                        await message.channel.send(embed=embeds.simple_embed(
                            True,
                            database.write_contract(
                                message.guild, message.author,
                                message.content.split("```")[1],
                                message.content.split(
                                    " ")[1], client, person_roles,
                                server_members, server_roles, person_id)[1]))
                        return
            if (commands.is_valid_command(message)):
                message_array = message.content.split(" ")
                message_command = message_array[0]
                if (message_command == "$help"):
                    await message.channel.send(embed=embeds.simple_embed(
                        "info", '''
- $help - shows all commands
- $send (from wallet) (to wallet) (amount) - sends an amount to a person from that wallet
- $print (wallet name) (amount) - creates an amount of money in that wallet if you have the role "printer"
- $balance (wallet name) - returns the amount of money in the wallet
- $links - show some links related to this bot
- $smart-contract (trigger) (code block) - code a smart contract
- $clear-contracts - delete all your smart contracts.
- $create (ping wallet) - create an account
- $whois (condition) - figure out who is a condition
- $send-each (from wallet) (ammount) (condition) - send each person who meets a condition
- $set-balance (ping wallet) - set the balance of a wallet for admins only
- $set-balance-each (amount) (condition) - set the balance of each person who meets a condition
- $wallet-settings (target person) (ping wallet) (setting name) (boolean) - change the setting, such as view or access, to allow certain people to do more with wallets
- $trade (wallet) (wanted currency) (giving up currency) (optional limitations) - create a trade
- $accept (message id of trade) (wallet) - accept a trade
- $quiz - start a quiz based on a subject
- $shop (item name) (price) - same as trade but only for admins and you can also offer roles as trades
- $work - get an amount of money no strings attached
- $work-conditional (level name) (work reward) (conditional) - allows admins to add levels to working and give different people different work rewards
                    '''))
                if (message_command == "$send"):
                    #send(person_roles, server_members, server_roles, person_id, guild_id, from_wallet, to_wallet, amount)
                    person_roles = list(
                        map(lambda role: role.id, message.author.roles))
                    server_members = list(
                        map(lambda member: member.id, message.guild.members))
                    server_roles = list(
                        map(lambda role: role.id, message.guild.roles))

                    send_result = database.send(message.author.id,
                                                message.guild,
                                                message_array[1],
                                                message_array[2],
                                                message_array[3])
                    await message.channel.send(embed=embeds.simple_embed(
                        send_result[0], send_result[1]))
                    #if  send_result[0]:
                    #   await message.channel.send(send_result[1])
                    #else:
                    #    await message.channel.send(f'an error occured {send_result[1]}')
                if (message_command == "$create"):
                    result = database.create(message.guild, message_array[1])
                    await message.channel.send(
                        embed=embeds.simple_embed(result[0], result[1]))

                if (message_command == "$balance"):
                    ##guild,wallet,server_members, server_roles
                    if len(message_array) == 1:
                        message_array.append(message.author.mention)
                    bal = database.get_balance(message.author, message.guild,
                                               message_array[1])
                    if (bal[0]):
                        res = ""
                        for key, value in bal[1].items():
                            if ("balance" in key):
                                res = res + f'{key}: {value}\n'
                        await message.channel.send(embed=embeds.simple_embed(
                            True, f'the balance is:\n {res}'))
                    else:
                        await message.channel.send(embed=embeds.simple_embed(
                            False, f'there was an error: {bal[1]}'))
                if (message_command == "$print"):
                    ##(discord_client, guild_id, wallet, amount)
                    result = database.print_money(message.author,
                                                  message.guild,
                                                  message_array[1],
                                                  message_array[2])
                    await message.channel.send(
                        embed=embeds.simple_embed(result[0], result[1]))
                if (message_command == "$clear-contracts"):
                    database.clear_contracts(message.guild, message.author.id)
                    await message.channel.send(embed=embeds.simple_embed(
                        "info", "your contracts were all deleted"))
                if (message_command == "$links"):
                    await message.channel.send(embed=embeds.simple_embed(
                        "info",
                        "Github - https://github.com/eulerthedestroyer/EU-Economy-Bot \n Discord link -  https://discord.gg/ghFs7ZM \n Bot link - https://discord.com/api/oauth2/authorize?client_id=716434826151854111&permissions=268503104m&scope=bot \n Web interface - https://economy-bot.atticuskuhn.repl.co"
                    ))
                if (message_command == "$config"):
                    if message.author.guild_permissions.administrator:
                        await message.channel.send(
                            embed=embeds.simple_embed(*database.set_config(
                                message.guild, message_array[1],
                                message_array[2])))
                    else:
                        await message.channel.send(embed=embeds.simple_embed(
                            False,
                            "you must be an administrator to access the config"
                        ))
                if message_command.startswith("$stats"):
                    result = methods.get_wallet(server_members, server_roles,
                                                message.guild.id,
                                                message_array[1])
                    if (result[0]):
                        print(result)
                        found_wallet = database.wallet_by_id(
                            message.guild, result[1])
                        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)
                            await message.channel.send(
                                file=discord.File('fig.jpg'))
                            os.remove("fig.jpg")
                            #await message.channel.send(found_wallet["record"])
                        else:
                            await message.channel.send(
                                embed=embeds.simple_embed(
                                    False, "can't find any stats"))
                    else:
                        await message.channel.send("error")
                if message_command == "$whois":
                    people = methods.whois(message_array[1:], message.guild)
                    return_statement = ""
                    symbol = "\n"
                    if len(people) > 7:
                        symbol = ","
                    for index, person in enumerate(people):
                        if len(return_statement) > 700:
                            return_statement += f' and {len(people)-index} others'
                            break
                        return_statement = return_statement + f'<@{person}>{symbol}'
                    if return_statement == "":
                        return_statement = "(no people found)"
                    embedVar = discord.Embed(
                        title="Result",
                        description=f'Found {len(people)} People',
                        color=0x00ff00)
                    embedVar.add_field(name="People",
                                       value=return_statement,
                                       inline=False)
                    await message.channel.send(embed=embedVar)
                if message_command == "$send-each":
                    people = methods.whois(message_array[3:], message.guild)
                    return_statement = ""
                    successful_transfer = True
                    for person in people:
                        send_result = database.send(message.author.id,
                                                    message.guild,
                                                    message_array[1],
                                                    f'<@{person}>',
                                                    message_array[2])
                        if send_result[0]:
                            return_statement = return_statement + f'<@{person}> - success\n'
                        else:
                            return_statement = return_statement + f'<@{person}> - error: {send_result[1]}\n'
                            successful_transfer = False
                    if return_statement == "":
                        return_statement = "(no people found)"
                    if successful_transfer:
                        embedVar = discord.Embed(title="Result",
                                                 color=0x00ff00)
                    else:
                        embedVar = discord.Embed(title="Result",
                                                 color=0xff0000)

                    embedVar.add_field(name="People",
                                       value=return_statement,
                                       inline=False)
                    await message.channel.send(embed=embedVar)
                if message_command == "$set-balance":
                    if (not message.author.guild_permissions.administrator):
                        await message.channel.send(
                            "you do not have administrator permissions")
                        return
                    result = database.set_money(message.guild,
                                                message_array[2],
                                                message_array[1])
                    await message.channel.send(embed=embeds.simple_embed(
                        result[0], f'{result[0]}{result[1]}'))
                if message_command == "$set-balance-each":
                    if (not message.author.guild_permissions.administrator):
                        await message.channel.send(
                            "you do not have administrator permissions")
                        return
                    people = methods.whois(message_array[2:], message.guild)
                    return_statement = ""
                    successful_transfer = True
                    for person in people:
                        send_result = database.set_money(
                            message.guild, message_array[1], f'<@{person}>')
                        if send_result[0]:
                            return_statement = return_statement + f'<@{person}> - success\n'
                        else:
                            return_statement = return_statement + f'<@{person}> - error: {send_result[1]}\n'
                            successful_transfer = False
                    if return_statement == "":
                        return_statement = "(no people found)"
                    if successful_transfer:
                        embedVar = discord.Embed(title="Result",
                                                 color=0x00ff00)
                    else:
                        embedVar = discord.Embed(title="Result",
                                                 color=0xff0000)

                    embedVar.add_field(name="People",
                                       value=return_statement,
                                       inline=False)
                    await message.channel.send(embed=embedVar)
                if message_command == "$wallet-settings":
                    res = database.set_settings(message.guild, message.author,
                                                message_array[1],
                                                message_array[2],
                                                message_array[3],
                                                message_array[4])
                    await message.channel.send(
                        embed=embeds.simple_embed(res[0], res[1]))
                if message_command == "$trade":
                    res = database.insert_trade(message, message.author,
                                                message.guild,
                                                message_array[1],
                                                message_array[2],
                                                message_array[3],
                                                message_array[4:])
                    await message.channel.send(
                        embed=embeds.simple_embed(res[0], res[1]))
                    if res[0]:
                        await message.add_reaction("✅")
                if message_command == "$accept":
                    res = database.fulfill_trade(message_array[1],
                                                 message_array[2],
                                                 message.author, message.guild)
                    await message.channel.send(
                        embed=embeds.simple_embed(res[0], res[1]))
                if message_command == "$quiz":
                    res = database.get_question(message.author, message.guild)
                    await message.channel.send(
                        embed=embeds.simple_embed(res[0], res[1]))
                if message_command == "$shop":
                    if not message.author.guild_permissions.administrator:
                        await message.channel.send(embed=embeds.simple_embed(
                            False,
                            "you must be an administrator to configure the shop"
                        ))
                        return
                    res = database.insert_trade(message, message.author,
                                                message.guild, "admins",
                                                message_array[1],
                                                message_array[2],
                                                message_array[3:])
                    await message.channel.send(
                        embed=embeds.simple_embed(res[0], res[1]))
                    if res[0]:
                        await message.add_reaction("✅")
                if message_command == "$work":
                    res = database.work(message.author, message.guild)
                    await message.channel.send(embed=embeds.simple_embed(*res))
                if message_command == "$work-conditional":
                    if not message.author.guild_permissions.administrator:
                        await message.channel.send(embed=embeds.simple_embed(
                            False,
                            "you must be an administrator to configure conditional work rewards"
                        ))
                        return
                    res = database.work_conditions(message.guild,
                                                   message_array[1],
                                                   message_array[2],
                                                   message_array[3:])
                    await message.channel.send(embed=embeds.simple_embed(*res))
            else:
                await message.channel.send(embed=embeds.simple_embed(
                    False,
                    "not valid command. If you want a list of all commands, type '$help' "
                ))
コード例 #6
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"))