Skip to content

Commit

Permalink
Merge pull request #1969 from avrae/nightly
Browse files Browse the repository at this point in the history
Nightly Merge
  • Loading branch information
SeanStoves committed Jan 12, 2024
2 parents adffbf4 + 2d358be commit 5ed54e7
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 14 deletions.
8 changes: 7 additions & 1 deletion cogs5e/initiative/cog.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
search_and_select,
try_delete,
camel_to_title,
ordinal,
)
from . import (
Combat,
Expand Down Expand Up @@ -996,7 +997,12 @@ async def effect(self, ctx, target_name: str, effect_name: str, *args):
targets = []

for i, t in enumerate([target_name] + args.get("t")):
target = await combat.select_combatant(ctx, t, f"Select target #{i + 1}.", select_group=True)
target = await combat.select_combatant(
ctx,
t,
f"Pick your {ordinal(i+1)} target.",
select_group=True,
)
if isinstance(target, CombatantGroup):
targets.extend(target.get_combatants())
else:
Expand Down
10 changes: 9 additions & 1 deletion cogs5e/models/homebrew/bestiary.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ async def from_bestiary_builder(cls, ctx, url):
except (ValueError, aiohttp.ContentTypeError):
raise ExternalImportError("Error importing bestiary: bad data. Are you sure the link is right?")

if raw.get("error", None):
raise ExternalImportError(f"Error importing bestiary: {raw['error']}")

creatures = raw["creatures"]
metadata = raw["metadata"]
name = metadata["name"]
Expand Down Expand Up @@ -367,7 +370,12 @@ def _monster_factory_bestiary_builder(data, bestiary_name):
attacks.extend(atks)
mythic_actions, atks = parse_bestiary_builder_traits(data, "mythic")
attacks.extend(atks)

# Avrae does not display these but we can at least parse their automation
_, atks = parse_bestiary_builder_traits(data, "lair")
attacks.extend(atks)
_, atks = parse_bestiary_builder_traits(data, "regional")
attacks.extend(atks)

name_duplications = {}
for atk in attacks:
if atk.name in name_duplications:
Expand Down
8 changes: 7 additions & 1 deletion cogs5e/utils/targetutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from cogs5e.models.character import Character
from cogs5e.models.errors import InvalidArgument, SelectionException
from utils.argparser import ParsedArguments, argparse
from utils.functions import ordinal

if TYPE_CHECKING:
from utils.context import AvraeContext
Expand Down Expand Up @@ -77,7 +78,12 @@ async def definitely_combat(ctx: "AvraeContext", combat: "Combat", args: ParsedA
contextargs = argparse(contextargs)

try:
target = await combat.select_combatant(ctx, t, f"Select target #{i + 1}.", select_group=allow_groups)
target = await combat.select_combatant(
ctx,
t,
f"Pick your {ordinal(i+1)} target.",
select_group=allow_groups,
)
except SelectionException:
raise InvalidArgument(f"Target {t} not found.")

Expand Down
6 changes: 3 additions & 3 deletions dbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@
from utils.help import help_command
from utils.redisIO import RedisIO

#This method will load the variables from .env into the environment for running in local
#from dotenv import load_dotenv
#load_dotenv()
# This method will load the variables from .env into the environment for running in local
# from dotenv import load_dotenv
# load_dotenv()


# -----COGS-----
Expand Down
2 changes: 1 addition & 1 deletion gamedata/monster.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ def from_data(cls, d):

@classmethod
def from_bestiary(cls, data, source):
for key in ("traits", "actions", "reactions", "legactions"):
for key in ("traits", "actions", "reactions", "legactions", "bonus_actions", "mythic_actions"):
data[key] = [Trait(**t) for t in data.pop(key)]
data["spellcasting"] = MonsterSpellbook.from_dict(data.pop("spellbook"))
data["saves"] = Saves.from_dict(data["saves"])
Expand Down
1 change: 0 additions & 1 deletion scripts/ensure_indices.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ def run(mdb):
if __name__ == "__main__":
mclient = MongoClient(os.getenv("MONGO_URL", "mongodb://localhost:27017"))


mdb = mclient[os.getenv("MONGO_DB", "avrae")]

input(f"Indexing on {mdb.name}. Press enter to continue.")
Expand Down
26 changes: 24 additions & 2 deletions utils/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ async def get_selection(
pm=False,
message=None,
force_select=False,
query=None,
):
"""Returns the selected choice, or raises an error.
If delete is True, will delete the selection message and the response.
Expand Down Expand Up @@ -148,7 +149,8 @@ def chk(msg):
names = [key(o) for o in _choices]
embed = disnake.Embed()
embed.title = "Multiple Matches Found"
select_str = "Which one were you looking for? (Type the number or `c` to cancel)\n"
select_str = f"Your input was: `{query}`\n" if query else ""
select_str += "Which one were you looking for? (Type the number or `c` to cancel)\n"
if len(pages) > 1:
select_str += "`n` to go to the next page, or `p` for previous\n"
embed.set_footer(text=f"Page {page + 1}/{len(pages)}")
Expand Down Expand Up @@ -258,7 +260,9 @@ async def search_and_select(
if len(results) == 1 and confidence > 75:
result = first_result
else:
result = await selector(ctx, results, key=selectkey or key, pm=pm, message=message, force_select=True)
result = await selector(
ctx, results, key=selectkey or key, pm=pm, message=message, force_select=True, query=query
)
if not return_metadata:
return result
metadata = {"num_options": 1 if strict else len(results), "chosen_index": 0 if strict else results.index(result)}
Expand Down Expand Up @@ -381,6 +385,24 @@ def smart_trim(text, max_len=1024, dots="[...]"):
return out


def ordinal(number: int) -> str:
"""
Converts an integer into its ordinal counterpart (eg. 1 -> 1st, 2 -> 2nd, 3 -> 3rd, etc...)
:param int number: Integer to convert
:return: Ordinal form of the given number
"""
ORDINAL_SUFFIXES = ("st", "nd", "rd", "th")

number = int(number)
if number // 10 == 1:
return f"{number}th"
else:
# index rolls over when number increases by 10, with the number shifted 1 to the left to match the 1st with a 1
index = min(3, (abs(number) - 1) % 10)
return f"{number}{ORDINAL_SUFFIXES[index]}"


# ==== misc helpers ====
def auth_and_chan(ctx):
"""Message check: same author and channel"""
Expand Down
6 changes: 2 additions & 4 deletions utils/img.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,11 @@ def process_img(the_img_bytes, template_fp="res/template-f.png"):

# crop/resize the token image
width, height = img.size
is_taller = height >= width
if is_taller:
if height >= width:
box = (0, 0, width, width)
else:
box = (width / 2 - height / 2, 0, width / 2 + height / 2, height)
img = img.crop(box)
img = img.resize(TOKEN_SIZE, Image.ANTIALIAS)
img = img.resize(TOKEN_SIZE, Image.Resampling.LANCZOS, box)

# paste mask
mask_img = Image.open("res/alphatemplate.tif")
Expand Down

0 comments on commit 5ed54e7

Please sign in to comment.