Ejemplo n.º 1
0
async def _unequip(tool):
    assigned_ids = utils.get_assigned_user_ids()

    if _unequip.message.author.id not in assigned_ids:
        await _unequip.message.channel.send(":warning: Your id is not assigned")

    else:
        if tool in statics.tools:
            filename = f"data/users/{_unequip.message.author.id}.ini"

            data = iniparser2.INI(convert_property=True)
            data.read_file(filename)

            if data["tools"][tool] is True:
                await _unequip.message.channel.send(
                    f":x: {_unequip.message.author.mention}, You are not equipping this tool: `{tool}`"
                )
                return

            data["tools"][tool] = True
            data.write(filename)

            await _unequip.message.channel.send(
                f":white_check_mark: {_unequip.message.author.mention}, You have unequipped tool **{tool}**"
            )
        else:
            await _unequip.message.channel.send(f":x: Tool `{tool}` did not exists")
Ejemplo n.º 2
0
async def _mine():
    assigned_ids = utils.get_assigned_user_ids()

    if _mine.message.author.id not in assigned_ids:
        await _mine.message.channel.send(":warning: Your id is not assigned")

    else:

        filename = f"data/users/{_mine.message.author.id}.ini"

        data = iniparser2.INI(convert_property=True)
        data.read_file(filename)

        if data["cooldown"]["mine"] > 0:
            await _mine.message.channel.send(
                f":warning: command is still cooling down for {utils.fsec(data['cooldown']['mine'])}"
            )

        else:

            rng = random.randint(0, len(statics.mine) - 1)
            mine_keys = [key for key in statics.mine.keys()]
            item = mine_keys[rng]
            rng_broken = random.randint(1, 3)

            data["cooldown"]["mine"] = 45
            data["stats"]["current_exp"] += 1.0

            if data["tools"]["pickaxe"] not in statics.items:
                await _mine.message.channel.send(f":x: Equip a pickaxe to mine"
                                                 )
                return

            try:
                result = statics.mine[item][data["tools"]["pickaxe"]]
            except KeyError:
                result = 0

            if rng_broken == 2:
                data["inventory"][data["tools"]["pickaxe"]] -= 1
                await _mine.message.channel.send(
                    f":warning: {_mine.message.author.mention}, Your {data['tools']['pickaxe']} is broken"
                )
                data["tools"]["pickaxe"] = True

            data["inventory"][item] += result
            data.write(filename)

            embed = discord.Embed(
                title="Mine",
                color=0xFF00FF,
            )

            if result > 0:
                embed.description = f"You mined x{result} `{item.upper()}`"
            else:
                embed.description = "You found nothing"
            embed.set_author(name=_mine.message.author.display_name)

            await _mine.message.channel.send(embed=embed)
Ejemplo n.º 3
0
async def update_user_database():
    users = utils.get_assigned_user_ids()

    for user in users:
        filename = f"data/users/{user}.ini"

        data = iniparser2.INI(convert_property=True)
        data.read_file(filename)

        if data.has_section("inventory") is False:
            data.set_section("inventory")

        for item in statics.items.keys():
            if data.has_property(item, section="inventory") is False:
                data["inventory"][item] = 0

        if data.has_section("cooldown") is False:
            data.set_section("cooldown")

        for cooldown in statics.cooldowns:
            if data.has_property(cooldown, section="cooldown") is False:
                data["cooldown"][cooldown] = 0

        if data.has_section("tools") is False:
            data.set_section("tools")

        for tool in statics.tools:
            if data.has_property(tool, section="tools") is False:
                data["tools"][tool] = True

        data.write(filename)
Ejemplo n.º 4
0
async def _buy(item, amount=1):
    try:
        amount = int(amount)
    except Exception:
        await _buy.message.channel.send(
            f":x: item amount must be an integer value.")
        return

    assigned_ids = utils.get_assigned_user_ids()

    if _buy.message.author.id not in assigned_ids:
        await _buy.message.channel.send(":warning: Your id is not assigned")

    else:

        filename = f"data/users/{_buy.message.author.id}.ini"

        data = iniparser2.INI(convert_property=True)
        data.read_file(filename)

        if item not in statics.items:
            await _buy.message.channel.send(f":x: Item `{item}` did not exists"
                                            )
            return

        if statics.items[item]["purchasable"] is False:
            await _buy.message.channel.send(
                f":x: You cannot buy this item, `{item}`")
            return

        if amount < 1:
            await _buy.message.channel.send(
                ":x: item amount cannot be lower than 1")
            return

        price = statics.items[item]["price"] * amount

        if data["stats"]["balance"] < amount:
            await _buy.message.channel.send(
                f":x: You need **{price}** coins to buy x{amount} `{item}`")
            return

        data["inventory"][item] += amount
        data["stats"]["balance"] -= price

        data.write(filename)

        embed = discord.Embed(title="Buy", color=0xFF00FF)
        embed.description = f"You bought x{amount} `{item}` for **{price}** coins"
        embed.set_author(name=_buy.message.author.display_name)

        await _buy.message.channel.send(embed=embed)
Ejemplo n.º 5
0
async def _chop():
    assigned_ids = utils.get_assigned_user_ids()

    if _chop.message.author.id not in assigned_ids:
        await _chop.message.channel.send(":warning: Your id is not assigned")

    else:
        filename = f"data/users/{_chop.message.author.id}.ini"

        data = iniparser2.INI(convert_property=True)
        data.read_file(filename)

        if data["cooldown"]["chop"] > 0:
            await _chop.message.channel.send(
                f":warning: command is still cooling down for {utils.fsec(data['cooldown']['chop'])}"
            )

        else:
            rng = random.randint(1, 3)

            if data["tools"]["axe"] in statics.chop:
                wood = statics.chop[data["tools"]["axe"]]

                if rng == 2:
                    data.set(
                        data["tools"]["axe"],
                        data["inventory"][data["tools"]["axe"]] - 1,
                        section="inventory",
                    )
                    await _chop.message.channel.send(
                        f":warning: {_chop.message.author.mention} Your `{data['tools']['axe']}` is broken!"
                    )
                    data.set("axe", True, section="tools")

            else:
                wood = 1

            data["inventory"]["wood"] += wood
            data["stats"]["current_exp"] += 1.0
            data["cooldown"]["chop"] = 30
            data.write(filename)

            embed = discord.Embed(
                title="Chop",
                description=f"You chopped x{wood} wood",
                color=0xFF00FF,
            )
            embed.set_author(name=_chop.message.author.display_name)

            await _chop.message.channel.send(embed=embed)
Ejemplo n.º 6
0
async def update_cooldown():
    userids = utils.get_assigned_user_ids()

    for userid in userids:
        filename = f"data/users/{userid}.ini"

        data = iniparser2.INI(convert_property=True)
        data.read_file(filename)

        for cooldown in data["cooldown"].keys():
            if data["cooldown"][cooldown] > 0:
                data["cooldown"][cooldown] -= 1

        data.write(filename)
Ejemplo n.º 7
0
async def _guild_leave():
    assigned_ids = utils.get_assigned_user_ids()

    if _guild_leave.message.author.id not in assigned_ids:
        await _guild_leave.message.channel.send(
            ":warning: Your id is not assigned")

    else:
        in_guild = False
        is_leader = False
        guild_id = -1

        for gid in utils.get_guilds_id():
            members = utils.get_guild_members_id(gid)

            guild = iniparser2.INI(convert_property=True)
            guild.read_file(f"data/guilds/{gid}.ini")

            if _guild_leave.message.author.id in members:
                in_guild = True
                guild_id = gid

            if _guild_leave.message.author.id == guild["info"]["leader"]:
                in_guild = False
                is_leader = True
                guild_id = gid

        if is_leader:
            await _guild_leave.message.channel.send(
                ":x: You can't leave if you are a leader of a guild, you can delete your guild"
            )
            return

        elif in_guild:
            filename = f"data/guilds/{guild_id}.ini"

            data = iniparser2.INI(convert_property=True)
            data.read_file(filename)

            del data["members"][str(_guild_leave.message.author.id)]
            data.write(filename)

            await _guild_leave.message.channel.send(
                f":white_check_mark: You left the guild: **{data['info']['name']}**"
            )

        else:
            await _guild_leave.message.channel.send(
                ":x: You are not in a guild")
Ejemplo n.º 8
0
async def _fish():
    assigned_ids = utils.get_assigned_user_ids()

    if _fish.message.author.id not in assigned_ids:
        await _fish.message.channel.send(":warning: Your id is not assigned")

    else:
        filename = f"data/users/{_fish.message.author.id}.ini"

        data = iniparser2.INI(convert_property=True)
        data.read_file(filename)

        if data["cooldown"]["fish"] > 0:
            await _fish.message.channel.send(
                f":x: Command is still cooling down for {utils.fsec(data['cooldown']['fish'])} minutes"
            )
            return

        if data["inventory"]["fishing_rod"] < 1:
            await _fish.message.channel.send(":x: You don't have a fishing rod"
                                             )
            return

        else:
            rng = random.randint(1, 3)
            rng_fish = random.randint(1, 3)

            if rng == 2:
                data["inventory"]["fising_rod"] -= 1
                await _fish.message.channel.send(
                    f":warning: {_fish.message.author.mention}, Your fishing rod is broken"
                )

            if rng_fish == 2:
                data["cooldown"]["fish"] = 60
                data["inventory"]["fish"] += 1
                data["stats"]["current_exp"] += 2.0

                await _fish.message.channel.send(
                    f"{_fish.message.author.mention}, You have caught a `fish`"
                )

            else:
                data["cooldown"]["fish"] = 60
                await _fish.message.channel.send(
                    f":x: you didn't catch anything")

        data.write(filename)
Ejemplo n.º 9
0
async def _inventory(page=1):
    try:
        page = int(page) - 1
    except Exception:
        await _inventory.message.channel.send(
            ":warning: use number to navigate between pages")
        return

    assigned_ids = utils.get_assigned_user_ids()

    if _inventory.message.author.id not in assigned_ids:
        await _inventory.message.channel.send(
            ":warning: Your id is not assigned")

    else:

        pages = [[]]
        filename = f"data/users/{_inventory.message.author.id}.ini"

        data = iniparser2.INI(convert_property=True)
        data.read_file(filename)

        for item in data["inventory"].keys():
            if len(pages[len(pages) - 1]) == 15:
                pages.append([])

            if len(pages[len(pages) - 1]) < 15:
                if data["inventory"][item] > 0:
                    pages[len(pages) -
                          1].append(f"{item}: {data['inventory'][item]}")

        if (page + 1) > len(pages) or (page + 1) < 1:
            await _inventory.message.channel.send(
                f":x: Page {page + 1} did not exists")

        else:
            if len(pages[0]) < 1:
                await _inventory.message.channel.send(
                    f":warning: You don't have any items")

            else:
                embed = discord.Embed(title="Inventory", color=0xFF00FF)
                embed.set_author(name=_inventory.message.author.display_name)
                embed.description = "```\n" + "\n".join(pages[page]) + "\n```"
                embed.set_footer(text=f"Page {page + 1} of {len(pages)}")

                await _inventory.message.channel.send(embed=embed)
Ejemplo n.º 10
0
async def _field_buy():
    assigned_ids = utils.get_assigned_user_ids()

    if _field_buy.message.author.id not in assigned_ids:
        await _field_buy.message.channel.send(
            ":warning: Your id is not assigned")

    else:

        fields = utils.get_fields()

        if _field_buy.message.author.id in fields:
            await _field_buy.message.channel.send(
                f":x: You already have a field")

        else:

            filename = f"data/fields/{_field_buy.message.author.id}.ini"
            user_filename = f"data/users/{_field_buy.message.author.id}.ini"

            user_data = iniparser2.INI(convert_property=True)
            user_data.read_file(user_filename)

            if user_data["stats"]["balance"] >= 1000:
                open(filename, "w").close()

                data = iniparser2.INI(convert_property=True)
                data.read_file(filename)

                # free plot woo
                data.set_section("plot0")
                data["plot0"]["plant"] = True
                data["plot0"]["progress"] = 0

                user_data.set("balance",
                              user_data["stats"]["balance"] - 1000,
                              section="stats")

                data.write(filename)
                user_data.write(user_filename)

                await _field_buy.message.channel.send(
                    ":white_check_mark: You bought a field")

            else:
                await _field_buy.message.channel.send(
                    ":x: You need 1000 coins to buy a new field")
Ejemplo n.º 11
0
async def update_exp():
    userids = utils.get_assigned_user_ids()

    for userid in userids:
        filename = f"data/users/{userid}.ini"

        data = iniparser2.INI(convert_property=True)
        data.read_file(filename)

        if data["stats"]["current_exp"] >= data["stats"]["max_exp"]:
            prev_exp = data["stats"]["current_exp"] - data["stats"]["max_exp"]

            data["stats"]["current_exp"] = 0.0 + prev_exp
            data["stats"]["max_exp"] *= 2
            data["stats"]["level"] += 1

        data.write(filename)
Ejemplo n.º 12
0
async def _guild_join(guild_id):
    try:
        guild_id = int(guild_id)

    except Exception:
        await _guild_join.message.channel.send(
            ":x: guild id is not an integer value")
        return

    assigned_ids = utils.get_assigned_user_ids()

    if _guild_join.message.author.id not in assigned_ids:
        await _guild_join.message.channel.send(
            ":warning: Your id is not assigned")

    else:
        in_guild = False
        guilds = utils.get_guilds()

        for gid in range(len(guilds)):
            members = utils.get_guild_members_id(gid)

            if _guild_join.message.author.id in members:
                in_guild = True

        if in_guild is True:
            await _guild_join.message.channel.send(
                ":x: You are already in a guild")
            return

        filename = f"data/guilds/{guild_id}.ini"

        if not os.path.isfile(filename):
            await _guild_join.message.channel.send(
                f":x: Guild id {guild_id} did not exists")
            return

        data = iniparser2.INI(convert_property=True)
        data.read_file(filename)

        data["members"][_guild_join.message.author.id] = None
        data.write(filename)

        await _guild_join.message.channel.send(
            f":white_check_mark: You have joined guild: `{guilds[guild_id]['name']}`"
        )
Ejemplo n.º 13
0
async def _use(item):
    assigned_ids = utils.get_assigned_user_ids()

    if _use.message.author.id not in assigned_ids:
        await _use.message.channel.send(":warning: Your id is not assigned")

    else:

        filename = f"data/users/{_use.message.author.id}.ini"

        data = iniparser2.INI(convert_property=True)
        data.read_file(filename)

        if item not in statics.items:
            await _use.message.channel.send(
                f":x: Item did not exists, `{item}`")
            return

        if item not in statics.consumable:
            await _use.message.channel.send(
                f":x: You cannot use this item, `{item}`")

        else:
            if data["inventory"][item] > 0:
                if data["status"]["health"] == data["status"]["max_health"]:
                    await _use.message.channel.send(
                        ":warning: Your Health is maxed out")
                    return

                if (data["status"]["health"] + statics.consumable[item]
                    ) > data["status"]["max_health"]:
                    data["status"]["health"] = data["status"]["max_health"]

                else:
                    data["status"]["health"] += statics.consumable[item]

                data["inventory"][item] -= 1

                data.write(filename)

                await _use.message.channel.send(
                    f":white_check_mark: {_use.message.author.mention}, You used the item `{item}`, health restored **{statics.consumable[item]} HP**"
                )
            else:
                await _use.message.channel.send(
                    f":x: You don't have that item, `{item}`")
Ejemplo n.º 14
0
async def _field_buyplot():
    assigned_ids = utils.get_assigned_user_ids()

    if _field_buyplot.message.author.id not in assigned_ids:
        await _field_buyplot.message.channel.send(
            ":warning: Your id is not assigned")

    else:
        fields = utils.get_fields()

        if _field_buyplot.message.author.id not in fields:
            await _field_buyplot.message.channel.send(
                f":x: You don't have a field")

        else:

            filename = f"data/fields/{_field_buyplot.message.author.id}.ini"
            user_filename = f"data/users/{_field_buyplot.message.author.id}.ini"

            data = iniparser2.INI(convert_property=True)
            user_data = iniparser2.INI(convert_property=True)
            data.read_file(filename)
            user_data.read_file(user_filename)

            if len(data.sections()) == 10:
                await _field_buyplot.message.channel.send(
                    ":x: You cannot buy more plots")

            else:
                price = 1000 * len(data.sections())

                if user_data["stats"]["balance"] >= price:
                    await _field_buyplot.message.channel.send(
                        f":white_check_mark: You bought a new field plot with id `{len(data.sections())}`"
                    )
                    data.set_section(f"plot{len(data.sections())}")
                    data[f"plot{len(data.sections()) - 1}"]["plant"] = True
                    data[f"plot{len(data.sections()) - 1}"]["progress"] = 0

                    user_data["stats"]["balance"] -= price

                    data.write(filename)
                    user_data.write(user_filename)
Ejemplo n.º 15
0
async def _field():
    assigned_ids = utils.get_assigned_user_ids()

    if _field.message.author.id not in assigned_ids:
        await _field.message.channel.send(":warning: Your id is not assigned")

    else:
        fields = utils.get_fields()

        if _field.message.author.id not in fields:
            await _field.message.channel.send(f":x: You don't have a field")

        else:

            filename = f"data/fields/{_field.message.author.id}.ini"

            data = iniparser2.INI(convert_property=True)
            data.read_file(filename)

            embed = discord.Embed(
                title=f"{_field.message.author.display_name}'s Field",
                color=0xFF00FF)

            for pid, plot in enumerate(data.sections()):
                if data[plot]["progress"] > 0 and data[plot][
                        "plant"] in statics.items:
                    embed.add_field(
                        name=f"Plot {pid}",
                        value=f"Growing {data[plot]['plant']}...",
                        inline=False,
                    )
                elif (data[plot]["progress"] == 0
                      and data[plot]["plant"] in statics.items):
                    embed.add_field(
                        name=f"Plot {pid}",
                        value=f"{data[plot]['plant']} is ready to be harvested",
                        inline=False,
                    )
                else:
                    embed.add_field(name=f"Plot {pid}",
                                    value="Empty",
                                    inline=False)
            await _field.message.channel.send(embed=embed)
Ejemplo n.º 16
0
async def _start():
    assigned_userids = utils.get_assigned_user_ids()

    if _start.message.author.id in assigned_userids:
        await _start.message.channel.send(":x: Your id has already assigned!")

    else:
        filename = f"data/users/{_start.message.author.id}.ini"

        open(filename, "w").close()

        data = iniparser2.INI(convert_property=True)

        data.set_section("stats")
        data["stats"]["balance"] = 500
        data["stats"]["level"] = 0
        data["stats"]["current_exp"] = 0.0
        data["stats"]["max_exp"] = 50.0

        data.set_section("status")
        data["status"]["health"] = 100.0
        data["status"]["max_health"] = 100.0

        data.set_section("inventory")
        for item in statics.items.keys():
            data["inventory"][item] = 0

        data.set_section("cooldown")
        for cooldown in statics.cooldowns:
            data["cooldown"][cooldown] = 0

        data.set_section("tools")
        for tool in statics.tools:
            data["tools"][tool] = True

        data.write(filename)

        await _start.message.channel.send(
            ":white_check_mark: Your id has successfully assigned!")
Ejemplo n.º 17
0
async def _balance():
    assigned_ids = utils.get_assigned_user_ids()

    if _balance.message.author.id not in assigned_ids:
        await _balance.message.channel.send(":warning: Your id is not assigned"
                                            )

    else:

        filename = f"data/users/{_balance.message.author.id}.ini"

        data = iniparser2.INI(convert_property=True)
        data.read_file(filename)

        embed = discord.Embed(
            title="Balance",
            description=f"You have `{data['stats']['balance']}` coins",
            color=0xFF00FF,
        )
        embed.set_author(name=_balance.message.author.display_name)

        await _balance.message.channel.send(embed=embed)
Ejemplo n.º 18
0
async def _forage():
    assigned_ids = utils.get_assigned_user_ids()

    if _forage.message.author.id not in assigned_ids:
        await _forage.message.channel.send(":warning: Your id is not assigned")

    else:
        filename = f"data/users/{_forage.message.author.id}.ini"

        data = iniparser2.INI(convert_property=True)
        data.read_file(filename)

        if data["cooldown"]["forage"] > 0:
            await _forage.message.channel.send(
                f":warning: command is still cooling down for {utils.fsec(data['cooldown']['forage'])}"
            )

        else:

            rng_result = random.randint(1, 5)
            rng_item = random.randint(0, len(statics.forage) - 1)
            item = statics.forage[rng_item]

            data["inventory"][item] += rng_result
            data["stats"]["current_exp"] += 1.0
            data["cooldown"]["forage"] = 15
            data.write(filename)

            embed = discord.Embed(
                title="Forage",
                description=f"You found x{rng_result} `{item}`",
                color=0xFF00FF,
            )
            embed.set_author(name=_forage.message.author.display_name)

            await _forage.message.channel.send(embed=embed)
Ejemplo n.º 19
0
async def _craft(item, amount=1):
    try:
        amount = int(amount)

    except Exception:
        await _craft.message.channel.send(
            ":x: item amount value is not an integer")
        return

    assigned_ids = utils.get_assigned_user_ids()

    if _craft.message.author.id not in assigned_ids:
        await _craft.message.channel.send(":warning: Your id is not assigned")

    else:
        if item not in statics.items.keys():
            await _craft.message.channel.send(
                f":x: Item `{item}` did not exists")
            return

        if item not in statics.craft.keys():
            await _craft.message.channel.send(
                f":x: Item `{item}` is not craftable")
            return

        if amount < 1:
            await _craft.message.channel.send(
                f":x: Amount cannot be lower than 1")

        filename = f"data/users/{_craft.message.author.id}.ini"

        data = iniparser2.INI(convert_property=True)
        data.read_file(filename)

        used = []

        for recipe in statics.craft[item]["recipes"]:
            if data["inventory"][recipe] < statics.craft[item]["recipes"][
                    recipe]:
                await _craft.message.channel.send(
                    f":x: item required x{statics.craft[item]['recipes'][recipe]} `{recipe}`"
                )
                return

            else:
                used.append(
                    f"x{statics.craft[item]['recipes'][recipe] * amount} {recipe}"
                )
                data["inventory"][recipe] -= (
                    statics.craft[item]["recipes"][recipe] * amount)

        data["inventory"][item] += (statics.craft[item]["result"] * amount)
        data.write(filename)

        embed = discord.Embed(title="Craft", color=0xFF00FF)
        embed.description = (
            f"Successfully crafted x{statics.craft[item]['result'] * amount} {item}\n"
        )
        embed.description = (embed.description + "\nItem used\n```" +
                             "\n".join(used) + "```")
        embed.set_author(name=_craft.message.author.display_name)

        await _craft.message.channel.send(embed=embed)
Ejemplo n.º 20
0
async def _field_harvest(plot):
    try:
        plot = int(plot)
    except Exception:
        await _field_harvest.message.channel.send(
            ":x: use number to select a plot")

    else:

        assigned_ids = utils.get_assigned_user_ids()

        if _field_harvest.message.author.id not in assigned_ids:
            await _field_harvest.message.channel.send(
                ":warning: Your id is not assigned")

        else:

            fields = utils.get_fields()

            if _field_harvest.message.author.id not in fields:
                await _field_harvest.message.channel.send(
                    f":x: You don't have a field")

            else:

                filename = f"data/fields/{_field_harvest.message.author.id}.ini"
                user_filename = f"data/users/{_field_harvest.message.author.id}.ini"

                data = iniparser2.INI(convert_property=True)
                user_data = iniparser2.INI(convert_property=True)
                data.read_file(filename)
                user_data.read_file(user_filename)

                if "plot" + str(plot) not in data.sections():
                    await _field_harvest.message.channel.send(
                        f":x: Plot id `{plot}` did not exists")

                else:

                    _plot = "plot" + str(plot)

                    if data[_plot]["plant"] in statics.items:

                        if data[_plot]["progress"] == 0:
                            user_data["inventory"][data[_plot]["plant"]] += 1
                            user_data["stats"]["current_exp"] += 10.0
                            await _field_harvest.message.channel.send(
                                f":white_check_mark: {_field_harvest.message.author.mention}, You've harvested item `{data[_plot]['plant']}` from plot id `{plot}`"
                            )
                            data[_plot]["plant"] = True

                            data.write(filename)
                            user_data.write(user_filename)

                        else:
                            await _field_harvest.message.channel.send(
                                f":warning: crop on plot id `{plot}` is not yet mature, will mature in {utils.fsec(data[_plot]['progress'])}"
                            )
                    else:
                        await _field_harvest.message.channel.send(
                            f":x: Plot id {plot} is empty")
Ejemplo n.º 21
0
async def _hunt():
    assigned_ids = utils.get_assigned_user_ids()

    if _hunt.message.author.id not in assigned_ids:
        await _hunt.message.channel.send(":warning: Your id is not assigned")

    else:
        filename = f"data/users/{_hunt.message.author.id}.ini"

        data = iniparser2.INI(convert_property=True)
        data.read_file(filename)

        if data["cooldown"]["hunt"] > 0:
            await _hunt.message.channel.send(
                f":warning: Command is still cooling down for {utils.fsec(data['cooldown']['hunt'])}"
            )

        else:
            rng = random.randint(0, len(statics.hunt) - 1)
            rng_break = random.randint(1, 3)
            keys = [key for key in statics.hunt.keys()]
            item = keys[rng]
            item_data = statics.hunt[item]

            if len(item_data) > 0 and data["tools"]["sword"] in item_data:
                if (
                    data["status"]["health"] - item_data[data["tools"]["sword"]]
                ) <= 0.0:
                    data["status"]["health"] = data["status"]["max_health"]
                    data["stats"]["current_exp"] = 0.0

                    if data["stats"]["level"] > 0:
                        data["stats"]["max_exp"] /= 2
                        data["stats"]["level"] -= 1

                    data["cooldown"]["hunt"] = 60

                    for tool in statics.tools:
                        if tool in statics.items:
                            data.set(
                                tool, data["inventory"]["tool"] - 1, section="inventory"
                            )
                            data.set(tool, True, section="tools")

                    await _hunt.message.channel.send(
                        f":skull: You got killed by: `{item}`, you lost a level, EXP and your equipped tools"
                    )
                else:
                    data["cooldown"]["hunt"] = 60
                    data["inventory"][item] += 1
                    data["status"]["health"] -= item_data[data["tools"]["sword"]]
                    data["stats"]["current_exp"] = 5.0

                    if rng_break == 2:
                        data["inventory"][data["tools"]["sword"]] -= 1
                        await _hunt.message.channel.send(
                            f":warning: Your `{data['tools']['sword']}` is broken"
                        )

                    embed = discord.Embed(title="hunt", color=0xFF00FF)
                    embed.description = f"You killed a(n) `{item}` and You lost {item_data[data['tools']['sword']]} Health Points"
                    embed.set_author(name=_hunt.message.author.display_name)

                    await _hunt.message.channel.send(embed=embed)

                    data["tools"]["sword"] = True

            elif len(item_data) == 0:
                data["cooldown"]["hunt"] = 60
                data["inventory"][item] += 1
                data["stats"]["current_exp"] = 5.0

                embed = discord.Embed(title="hunt", color=0xFF00FF)
                embed.description = f"You killed a(n) `{item}`"
                embed.set_author(name=_hunt.message.author.display_name)

                await _hunt.message.channel.send(embed=embed)

            else:
                data.set("hunt", 60, section="cooldown")
                await _hunt.message.channel.send("You found nothing")

            data.write(filename)
Ejemplo n.º 22
0
async def _field_plant(seed, plot):
    try:
        plot = int(plot)
    except Exception:
        await _field_plant.message.channel.send(
            ":x: use number to select a plot")

    else:

        assigned_ids = utils.get_assigned_user_ids()

        if _field_plant.message.author.id not in assigned_ids:
            await _field_plant.message.channel.send(
                ":warning: Your id is not assigned")

        else:

            fields = utils.get_fields()

            if _field_plant.message.author.id not in fields:
                await _field_plant.message.channel.send(
                    f":x: You don't have a field")

            else:

                if seed not in statics.items:
                    await _field_plant.message.channel.send(
                        f":x: Item `{seed}` did not exists")
                    return

                if not seed.endswith("_seed"):
                    await _field_plant.message.channel.send(
                        f":x: You cannot plant this item: `{seed}`")
                    return

                filename = f"data/fields/{_field_plant.message.author.id}.ini"
                seedfor = seed.split("_seed")[0]

                data = iniparser2.INI(convert_property=True)
                data.read_file(filename)

                if "plot" + str(plot) not in data.sections():
                    await _field_plant.message.channel.send(
                        f":x: Plot id `{plot}` did not exists")

                else:
                    _plot = "plot" + str(plot)

                    if (data[_plot]["progress"] > 0
                            or data[_plot]["plant"] in statics.items):
                        await _field_plant.message.channel.send(
                            f":x: Plot id `{plot}` is not empty")

                    else:
                        data[_plot]["progress"] = statics.farm[seedfor]
                        data[_plot]["plant"] = seedfor

                        data.write(filename)

                        await _field_plant.message.channel.send(
                            f":white_check_mark: {_field_plant.message.author.mention}, You have planted `{seed}`, takes {utils.fsec(statics.farm[seedfor])} to mature."
                        )
Ejemplo n.º 23
0
async def _equip(item):
    assigned_ids = utils.get_assigned_user_ids()

    if _equip.message.author.id not in assigned_ids:
        await _equip.message.channel.send(":warning: Your id is not assigned")

    else:

        if item in statics.items:
            if item.endswith("_axe"):
                filename = f"data/users/{_equip.message.author.id}.ini"

                data = iniparser2.INI(convert_property=True)
                data.read_file(filename)

                if data["inventory"][item] < 1:
                    await _equip.message.channel.send(
                        f":x: {_equip.message.author.mention} You don't have this item `{item}`"
                    )
                    return

                data["tools"]["axe"] = item
                data.write(filename)

                await _equip.message.channel.send(
                    f":white_check_mark: {_equip.message.author.mention} You have equipped item: **{item}**"
                )

            elif item.endswith("_pickaxe"):
                filename = f"data/users/{_equip.message.author.id}.ini"

                data = iniparser2.INI(convert_property=True)
                data.read_file(filename)

                if data["inventory"][item] < 1:
                    await _equip.message.channel.send(
                        f":x: {_equip.message.author.mention} You don't have this item `{item}`"
                    )
                    return

                data["tools"]["pickaxe"] = item
                data.write(filename)

                await _equip.message.channel.send(
                    f":white_check_mark: {_equip.message.author.mention} You have equipped item: **{item}**"
                )

            elif item.endswith("_sword"):
                filename = f"data/users/{_equip.message.author.id}.ini"

                data = iniparser2.INI(convert_property=True)
                data.read_file(filename)

                if data["inventory"][item] < 1:
                    await _equip.message.channel.send(
                        f":x: {_equip.message.author.mention} You don't have this item `{item}`"
                    )
                    return

                data["tools"]["sword"] = item
                data.write(filename)

                await _equip.message.channel.send(
                    f":white_check_mark: {_equip.message.author.mention} You have equipped item: **{item}**"
                )

            else:
                await _equip.message.channel.send(
                    f":x: Item `{item}` is not equipable")

        else:
            await _equip.message.channel.send(
                f":x: Item `{item}` did not exists")
Ejemplo n.º 24
0
async def _profile(mention):
    mention_id = utils.mention_to_id(mention)
    mention = await _profile.client.fetch_user(mention_id)
    if not isinstance(mention, discord.User):
        await _profile.message.channel.send(":x: mention is invalid")
        return

    assigned_ids = utils.get_assigned_user_ids()

    if mention.id not in assigned_ids:
        await _profile.message.channel.send(
            ":warning: The mentioned user does not have their id assigned")

    else:
        filename = f"data/users/{mention.id}.ini"
        guild = None
        own_guild = None
        guilds = utils.get_guilds()

        for gid in range(len(guilds)):
            members = utils.get_guild_members_id(gid)

            if mention.id in members:
                guild = utils.get_guilds()[gid]

            if mention.id == int(guilds[gid]["leader"]):
                guild = None
                own_guild = guilds[gid]

        data = iniparser2.INI(convert_property=True)
        data.read_file(filename)

        embed = discord.Embed(title="Player Info", color=0xFF00FF)
        embed.set_author(name=mention.display_name)
        embed.set_footer(
            text=f"Requested by {_profile.message.author.display_name}")

        if guild is not None:
            embed.description = f"Guild: `{guild['name']}``\n\n"
        elif own_guild is not None:
            embed.description = f"[Leader] Guild: `{own_guild['name']}`\n\n"
        else:
            embed.description = ""

        stats_value = f"**Level**: {data['stats']['level']} ({int((data['stats']['current_exp']/data['stats']['max_exp']) * 100.0)}%)\n**EXP**: {data['stats']['current_exp']}/{data['stats']['max_exp']}\n**Balance**: {data['stats']['balance']} coin(s)"
        status_value = (
            f"**Health**: {data['status']['health']}/{data['status']['max_health']}"
        )
        equipment_value = ""
        for tool in statics.tools:
            if data["tools"][tool] in statics.items:
                equipment_value += f"**{tool.capitalize()}**: `{data['tools'][tool]}`\n"
            else:
                equipment_value += f"**{tool.capitalize()}**: `none`\n"

        embed.add_field(name="Stats", value=stats_value, inline=False)
        embed.add_field(name="Status", value=status_value, inline=False)
        embed.add_field(name="Equipment", value=equipment_value, inline=False)

        embed.set_thumbnail(url=mention.avatar_url)

        await _profile.message.channel.send(embed=embed)
Ejemplo n.º 25
0
async def _guild_create(name):
    assigned_ids = utils.get_assigned_user_ids()

    if _guild_create.message.author.id not in assigned_ids:
        await _guild_create.message.channel.send(
            ":warning: Your id is not assigned")

    else:
        if len(name) < 3:
            await _guild_create.message.channel.send(
                ":x: Guild name is too short, min 3 characters")

        else:
            for gid in utils.get_guilds_id():
                members = utils.get_guild_members_id(gid)

                if _guild_create.message.author.id in members:
                    await _guild_create.message.channel.send(
                        f":x: {_guild_create.message.author.mention}, You are already in a guild"
                    )
                    return

            names = utils.get_guilds_name()

            if name in names:
                await _guild_create.message.channel.send(
                    f":x: A guild with the name `{name}` already exists")

            else:
                gid = utils.new_guild_id()
                filename = f"data/guilds/{gid}.ini"
                user_filename = f"data/users/{_guild_create.message.author.id}.ini"

                user_data = iniparser2.INI(convert_property=True)
                user_data.read_file(user_filename)

                if user_data["stats"]["balance"] < 10_000:
                    await _guild_create.message.channel.send(
                        ":x: You don't have enough coins to create a new guild, coins required 10,000"
                    )
                    return

                if user_data["stats"]["level"] < 5:
                    await _guild_create.message.channel.send(
                        ":x: You must be at least level 5 to create a new guild"
                    )
                    return

                open(filename, "w").close()

                data = iniparser2.INI(convert_property=True)
                data.set_section("info")
                data["info"]["name"] = name
                data["info"]["leader"] = _guild_create.message.author.id
                data["info"]["created"] = datetime.datetime.utcnow()
                data["info"]["logo"] = "no logo"

                data.set_section("stats")
                data["stats"]["level"] = 0
                data["stats"]["current_exp"] = 0.0
                data["stats"]["max_exp"] = 100.0

                data.set_section("members")
                data.set(_guild_create.message.author.id,
                         True,
                         section="members")

                user_data.set("balance",
                              user_data["stats"]["balance"] - 10_000,
                              section="stats")

                data.write(filename)
                user_data.write(user_filename)

                await _guild_create.message.channel.send(
                    f":white_check_mark: Guild has successfully created with id `{gid}`"
                )