コード例 #1
0
async def rename_kingdom(ctx, *args):
    # Check if session exists
    if await management.check_session_exists(ctx):
        return

    else:
        management.add_session(ctx)

    # User doesn't have a kingdom
    if not check_has_kingdom(ctx):
        await handle_no_kingdom(ctx)
        management.remove_session(ctx)
        return

    if len(args) == 0:
        await ctx.channel.send(">>> Please use the commnd `" + cfg.PREFIX +
                               "rename <new name>` to rename your kingdom.")
        management.remove_session(ctx)
        return

    new_name = " ".join(args[0:])

    await ctx.channel.send(
        ">>> Are you sure you would like to name your kingdom **" + new_name +
        "**? (y/n)")

    # Pre-condition check for wait_for function
    def check(msg):
        return msg.content.lower() in {"y", "n"
                                       } and msg.author.id == ctx.author.id

    try:
        msg = await bot.wait_for("message",
                                 check=check,
                                 timeout=cfg.config["reply_timeout"])

    except asyncio.TimeoutError:
        await ctx.channel.send(
            ">>> You took too long to reply! Command cancelled.")
        management.remove_session(ctx)
        return

    # User cancelled the kingdom creation
    if msg.content.lower() == "n":
        await ctx.channel.send(">>> Kingdom rename cancelled!")
        management.remove_session(ctx)
        return

    cfg.db_cur.execute("UPDATE Kingdoms SET k_name=? WHERE uid=?;",
                       (new_name, str(ctx.author.id)))
    cfg.db_con.commit()

    await ctx.channel.send(">>> Kingdom renamed to **" + new_name + "**.")

    management.remove_session(ctx)
コード例 #2
0
async def init_kingdom(ctx, *args):
    # Check if session exists
    if await management.check_session_exists(ctx):
        return

    else:
        management.add_session(ctx)

    # User already has a kingdom
    if check_has_kingdom(ctx):
        await handle_existing_kingdom(ctx)
        management.remove_session(ctx)
        return

    # Incorrect number of arguments
    if len(args) == 0:
        await handle_no_kingdom(ctx)
        management.remove_session(ctx)
        return

    kingdom_name = " ".join(args[0:])

    await ctx.channel.send(
        ">>> Are you sure you would like to name your kingdom **" +
        kingdom_name + "**? (y/n)")

    # Pre-condition check for wait_for function
    def check(msg):
        return msg.content.lower() in {"y", "n"
                                       } and msg.author.id == ctx.author.id

    try:
        msg = await bot.wait_for("message",
                                 check=check,
                                 timeout=cfg.config["reply_timeout"])

    except asyncio.TimeoutError:
        await ctx.channel.send(
            ">>> You took too long to reply! Command cancelled.")
        management.remove_session(ctx)
        return

    # User cancelled the kingdom creation
    if msg.content.lower() == "n":
        await ctx.channel.send(">>> Kingdom creation cancelled!")
        management.remove_session(ctx)
        return

    create_kingdom(ctx, kingdom_name)

    await ctx.channel.send(">>> Kingdom **" + kingdom_name + "** created!")

    management.remove_session(ctx)
コード例 #3
0
async def show_tax_rate(ctx):
    # Check if session exists
    if await management.check_session_exists(ctx):
        return

    else:
        management.add_session(ctx)

    tax_rate = get_tax_rate()

    to_send = ">>> "
    to_send += "The current tax rate for today is `" + str(tax_rate)
    to_send += "` doubloons per Rumplin."

    await ctx.channel.send(to_send)

    management.remove_session(ctx)
コード例 #4
0
async def collect_tax(ctx):
    # Check if session exists
    if await management.check_session_exists(ctx):
        return

    else:
        management.add_session(ctx)

    # Check if user has a kingdom
    if not kingdoms.check_has_kingdom(ctx):
        await kingdoms.handle_no_kingdom(ctx)
        management.remove_session(ctx)
        return

    # Check if user has already collected tax
    if check_tax_collected_today(ctx):
        to_send = ">>> "
        to_send += "You already collected tax today! You can collect tax again in **"
        to_send += get_collect_time_remaining(ctx)
        to_send += "**!"

        await ctx.channel.send(to_send)

        management.remove_session(ctx)
        return

    # Count the total population of a kingdom
    cfg.db_cur.execute(
        "SELECT SUM(v.population) as total_pop, COUNT(v.vid) as num_villages FROM Villages v, Kingdoms k WHERE v.kid=k.kid AND k.uid=?;",
        (str(ctx.author.id), ),
    )
    result = cfg.db_cur.fetchone()

    if result["num_villages"] == 0:
        await ctx.channel.send(
            ">>> You need to have at least one village before you can collect taxes!"
        )
        management.remove_session(ctx)
        return

    total_pop = result["total_pop"]
    tax_collected = calculate_tax_amount(total_pop)
    num_villages = result["num_villages"]

    add_doubloons(ctx, tax_collected)
    update_tax_collected(ctx)

    await send_tax_collected_message(ctx, tax_collected, num_villages,
                                     total_pop)

    management.remove_session(ctx)
コード例 #5
0
async def levelup_rank(ctx):
    # Check if session exists
    if await management.check_session_exists(ctx):
        return

    else:
        management.add_session(ctx)

    cfg.db_cur.execute("SELECT rank, rumpus_count FROM Users WHERE uid=?;",
                       (str(ctx.author.id), ))
    result = cfg.db_cur.fetchone()

    rank = result["rank"]
    r_count = result["rumpus_count"]

    if (rank + 1) >= len(cfg.config["ranks"]):
        await ctx.channel.send(
            ">>> You are already the highest rank! Congratulations!")

        management.remove_session(ctx)
        return

    new_rank = cfg.config["ranks"][rank + 1]
    needed_to_upgrade = new_rank["count"]

    if r_count >= needed_to_upgrade:
        upgrade_level(ctx, rank + 1)
        currency.add_doubloons(ctx, new_rank["reward"])

        to_send = ">>> Wow! You've upgraded to the rank of **"
        to_send += new_rank["name"]
        to_send += "**! You've been awarded `"
        to_send += str(new_rank["reward"])
        to_send += "` doubloons!"

        await ctx.channel.send(to_send)

    else:
        to_send = ">>> Sorry, you need `"
        to_send += str(needed_to_upgrade - r_count)
        to_send += "` more rumpuses to upgrade to the next level!"

        await ctx.channel.send(to_send)

        management.remove_session(ctx)
        return

    management.remove_session(ctx)
コード例 #6
0
async def village_options(ctx, *args):
    # Check if session exists
    if await management.check_session_exists(ctx):
        return

    else:
        management.add_session(ctx)

    # Check if user has a kingdom
    if not kingdoms.check_has_kingdom(ctx):
        await kingdoms.handle_no_kingdom(ctx)
        management.remove_session(ctx)
        return

    if len(args) == 0:
        await show_village_help(ctx)
        management.remove_session(ctx)
        return

    action = args[0].lower()

    if action == "list":
        await list_villages(ctx)

    elif action == "buy":
        if len(args) < 2:
            await ctx.channel.send(
                ">>> Use the command `" + cfg.PREFIX +
                "village buy <name>` to purchase a new village.")
            management.remove_session(ctx)
            return

        await buy_village(ctx, args)

    elif action == "upgrade":
        if len(args) < 2:
            await ctx.channel.send(
                ">>> Use the command `" + cfg.PREFIX +
                "village upgrade <index>` to upgrade a village.")
            management.remove_session(ctx)
            return

        await upgrade_village(ctx, args)

    elif action == "rename":
        if len(args) < 3:
            await ctx.channel.send(
                ">>> Use the command `" + cfg.PREFIX +
                "village rename <index> <name>` to rename a village.")
            management.remove_session(ctx)
            return

        await rename_village(ctx, args)

    else:
        await show_village_help(ctx)

    management.remove_session(ctx)
コード例 #7
0
async def attack_user(ctx):
    # Check if session exists
    if await management.check_session_exists(ctx):
        return

    else:
        management.add_session(ctx)

    # Check if user has a kingdom
    if not kingdoms.check_has_kingdom(ctx):
        await kingdoms.handle_no_kingdom(ctx)
        management.remove_session(ctx)
        return

    if not await check_attack_prereqs(ctx):
        management.remove_session(ctx)
        return

    all_kingdoms = get_all_non_attacked_kingdoms(ctx)
    converted_all_kingdoms = shared.convert_id_to_name_key(
        all_kingdoms, "uid", "username"
    )

    if len(all_kingdoms) == 0:
        await ctx.channel.send(
            ">>> There are currently no kingdoms that can be attacked!"
        )
        management.remove_session(ctx)
        return

    attacked_kingdom = await choose_kingdom_to_attack(ctx, converted_all_kingdoms)
    if not attacked_kingdom:
        management.remove_session(ctx)
        return

    number_attack_units = await choose_number_attack_units(ctx)
    if not number_attack_units:
        management.remove_session(ctx)
        return

    attacked_kingdom_units = get_number_units(str(attacked_kingdom["uid"]))

    if number_attack_units > attacked_kingdom_units["defence"]:
        await handle_successful_attack(ctx, attacked_kingdom, number_attack_units)

    else:
        await handle_failed_attack(ctx, attacked_kingdom, number_attack_units)

    management.remove_session(ctx)
コード例 #8
0
async def buy_troops(ctx, *args):
    # Check if session exists
    if await management.check_session_exists(ctx):
        return

    else:
        management.add_session(ctx)

    # User doesn't have a kingdom
    if not check_has_kingdom(ctx):
        await handle_no_kingdom(ctx)
        management.remove_session(ctx)
        return

    # Show purchase options
    if len(args) == 0:
        await show_shop_help(ctx)

        management.remove_session(ctx)
        return

    action = args[0].lower()

    if action == "list":
        await show_purchase_options(ctx)

        management.remove_session(ctx)
        return

    elif action == "buy":
        if len(args) < 2 or not args[1].isnumeric():
            await ctx.channel.send(
                ">>> Use the command `" + cfg.PREFIX +
                "shop buy <index> [amount]` to purchase a new unit.")

            management.remove_session(ctx)
            return

        await purchase_unit(ctx, args)

    else:
        await show_shop_help(ctx)

        management.remove_session(ctx)
        return

    management.remove_session(ctx)