Exemple #1
0
async def arrange_trade(team: str, partner: str, items) -> DiscordAction:
    pair_list = []
    try:
        pair_list = to_pair_list(items)
    except ValueError as _:
        return Message("Input list is badly formatted.")
    sub = get_sub(team)
    partner_sub = get_sub(partner)
    if sub and partner_sub:
        return Message(await sub.inventory.begin_trade(partner_sub, pair_list))
    return Message("Didn't recognise the submarine asked for.")
Exemple #2
0
async def make_offer(team: str, items) -> DiscordAction:
    try:
        pair_list = to_pair_list(items)
    except ValueError as _:
        return Message("Input list is badly formatted.")
    if pair_list is None:
        return Message("Input list is badly formatted.")

    async def do_offer(sub):
        return Message(await sub.inventory.make_offer(pair_list))

    return await with_sub_async(team, do_offer, FAIL_REACT)
Exemple #3
0
def zoom_in(x: int, y: int, loop) -> DiscordAction:
    if in_world(x, y):
        report = f"Report for square **({x}, {y})**\n"
        # since in_world => get_square : Cell (not None)
        report += get_square(x, y).square_status() + "\n\n"  # type: ignore
        # See if any subs are here, and if so print their status.
        subs_in_square = filtered_teams(
            lambda sub: sub.movement.x == x and sub.movement.y == y)
        for sub in subs_in_square:
            report += sub.status_message(loop) + "\n\n"
        return Message(report)
    return Message("Chosen square is outside the world boundaries!")
Exemple #4
0
async def print_map(team: str,
                    options: Sequence[str] = ("w", "d", "s", "a", "m", "e"),
                    show_hidden: bool = False) -> DiscordAction:
    """
    Prints the map from the perspective of one submarine, or all if team is None.
    """
    subs = []
    max_options = ["w", "d", "s", "t", "n", "a", "j", "m", "e"]
    if options is True:
        options = MAX_OPTIONS
    options = list(filter(lambda v: v in max_options, options))
    if team is None:
        subs = get_sub_objects()
    else:
        sub = get_sub(team)
        if sub is None:
            return FAIL_REACT
        else:
            subs = [sub]
    map_string, map_arr = draw_map(subs, list(options), show_hidden)
    map_json = json.dumps(map_arr)
    async with httpx.AsyncClient() as client:
        url = MAP_DOMAIN + "/api/map/"
        res = await client.post(url,
                                data={
                                    "map": map_string,
                                    "key": MAP_TOKEN,
                                    "names": map_json
                                })
        if res.status_code == 200:
            final_url = MAP_DOMAIN + res.json()['url']
            return Message(f"The map is visible here: {final_url}")
    return FAIL_REACT
Exemple #5
0
 async def do_add(sub):
     message = sub.upgrades.add_keyword(keyword, turn_limit, damage)
     if message is not None:
         await sub.send_message(
             f"Submarine **{team.title()}** was upgraded with the keyword **{keyword}**!",
             "engineer")
         return Message(message)
     return FAIL_REACT
Exemple #6
0
 async def do_broadcast(sub):
     if sub.power.activated():
         result = await sub.comms.broadcast(message)
         if result:
             return OKAY_REACT
         return Message(
             "The radio is still in use! (It has a thirty second cooldown.)"
         )
     return FAIL_REACT
Exemple #7
0
 async def do_set(sub):
     if sub.power.activated() == value:
         return Message(f"{team.title()} activation unchanged.")
     sub.power.activate(value)
     if sub.power.activated():
         await sub.undocking(guild)
         await sub.send_to_all(
             f"{team.title()} is **ON** and running! Current direction: **{sub.movement.get_direction().upper()}**."
         )
         return OKAY_REACT
     await sub.send_to_all(f"{team.title()} is **OFF** and halted!")
     return OKAY_REACT
Exemple #8
0
 async def do_offer(sub):
     return Message(await sub.inventory.make_offer(pair_list))
Exemple #9
0
 def do_unpower(sub):
     result = sub.power.unpower_systems(systems)
     return Message(result)
Exemple #10
0
 def do_scan(sub):
     message = sub.scan.previous_scan()
     if message != "":
         return Message(message)
     return Message("No scan done yet!")
Exemple #11
0
 async def do_interact(sub):
     message = await interact_in_square(sub, sub.movement.get_position(),
                                        arg)
     if message != "":
         return Message(message)
     return Message("Nothing to report.")
Exemple #12
0
 async def do_exit(sub):
     message = await sub.docking(guild)
     return Message(message)
Exemple #13
0
 async def do_broadcast(sub):
     if sub.power.activated():
         return Message(await sub.comms.broadcast(message))
     return FAIL_REACT
Exemple #14
0
def list_resources() -> DiscordAction:
    return Message(
        f"Available resources are: {str(RESOURCES)} with currency {CURRENCY_NAME}."
    )
Exemple #15
0
def list_keywords() -> DiscordAction:
    message = ""
    for upgrade in VALID_UPGRADES:
        message += f"`{upgrade}`: {VALID_UPGRADES[upgrade]}\n"
    return Message(message)
Exemple #16
0
 async def do_accept(sub):
     return Message(await sub.inventory.accept_trade())
Exemple #17
0
 async def do_reject(sub):
     return Message(await sub.inventory.reject_trade())
Exemple #18
0
 def do_crane(sub):
     return Message(sub.inventory.drop_crane())
Exemple #19
0
 def drop(sub):
     return Message(sub.inventory.drop(item))
Exemple #20
0
def add_npc_to_map(ntype: str, x: int, y: int,
                   team: Optional[str]) -> DiscordAction:
    sub = None
    if team and get_sub(team):
        sub = team
    return Message(add_npc(ntype, x, y, sub))
Exemple #21
0
 def do_status(sub):
     status_message = sub.status_message(loop)
     return Message(status_message)
Exemple #22
0
def printout_npc_types() -> DiscordAction:
    types = list_to_and_separated(get_npc_types())
    return Message(f"Possible NPC types: {types}.")
Exemple #23
0
 def do_schedule(sub):
     return Message(sub.weapons.prepare_shot(damaging, x, y))
Exemple #24
0
 def do_scan(sub):
     return Message(sub.scan.previous_scan())