1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-23 11:34:18 +00:00
This commit is contained in:
Steffo 2020-09-16 02:37:31 +02:00
parent ada3fb1643
commit 2160aca582
19 changed files with 850 additions and 605 deletions

798
poetry.lock generated

File diff suppressed because it is too large Load diff

View file

@ -2,10 +2,10 @@
[tool.poetry] [tool.poetry]
name = "rpgpack" name = "rpgpack"
version = "5.9.1" version = "5.9.2"
description = "A Dungeons & Dragons utilities pack for Royalnet" description = "A Dungeons & Dragons utilities pack for Royalnet"
authors = ["Stefano Pigozzi <ste.pigozzi@gmail.com>"] authors = ["Stefano Pigozzi <ste.pigozzi@gmail.com>"]
license = "AGPL-3.0+" license = "AGPL-3.0-or-later"
readme = "README.md" readme = "README.md"
homepage = "https://github.com/Steffo99/rpgpack" homepage = "https://github.com/Steffo99/rpgpack"
classifiers = [ classifiers = [
@ -22,11 +22,18 @@
sortedcontainers = "^2.1.0" sortedcontainers = "^2.1.0"
aiohttp = "^3.5" aiohttp = "^3.5"
# Required by poetry?!
bcrypt = "3.2.0"
sqlalchemy = "1.3.19"
[tool.poetry.dependencies.royalnet] [tool.poetry.dependencies.royalnet]
version = "~5.10.0" version = "~5.11.12"
extras = [ extras = [
"telegram",
"alchemy_easy", "alchemy_easy",
"herald",
"telegram",
"discord",
"constellation",
] ]
# Development dependencies # Development dependencies

View file

@ -10,18 +10,20 @@ from ...utils import get_targets
class DndBattleTargetCommand(rc.Command, abc.ABC): class DndBattleTargetCommand(rc.Command, abc.ABC):
@abc.abstractmethod @abc.abstractmethod
async def _change(self, unit: DndBattleUnit, args: List[str]): async def _change(self, unit: DndBattleUnit, args: List[str]):
... raise NotImplementedError()
async def run(self, args: rc.CommandArgs, data: rc.CommandData) -> None: async def run(self, args: rc.CommandArgs, data: rc.CommandData) -> None:
target = args[0] target = args[0]
units = await get_targets(data, target)
async with data.session_acm() as session:
units = await get_targets(target, data=data, session=session)
if len(units) == 0: if len(units) == 0:
raise rc.InvalidInputError(f"No targets found matching [c]{target}[/c].") raise rc.InvalidInputError(f"No targets found matching [c]{target}[/c].")
for unit in units: for unit in units:
await self._change(unit, args[1:]) await self._change(unit, args[1:])
await data.session_commit() await session.commit()
message = [] message = []
for unit in units: for unit in units:

View file

@ -16,8 +16,10 @@ class DndactiveCommand(Command):
async def run(self, args: CommandArgs, data: CommandData) -> None: async def run(self, args: CommandArgs, data: CommandData) -> None:
identifier = args.optional(0) identifier = args.optional(0)
author = await data.get_author(error_if_none=True)
active_character = await get_active_character(data) async with data.session_acm() as session:
author = await data.find_author(session=session, required=True)
active_character = await get_active_character(session=session, data=data)
DndCharacterT = self.alchemy.get(DndCharacter) DndCharacterT = self.alchemy.get(DndCharacter)
DndActiveCharacterT = self.alchemy.get(DndActiveCharacter) DndActiveCharacterT = self.alchemy.get(DndActiveCharacter)
@ -34,9 +36,11 @@ class DndactiveCommand(Command):
try: try:
identifier = int(identifier) identifier = int(identifier)
except ValueError: except ValueError:
chars = await asyncify(data.session.query(DndCharacterT).filter_by(name=identifier).all) chars = await asyncify(session.query(DndCharacterT).filter_by(name=identifier).all)
if len(chars) >= 2: if len(chars) >= 2:
char_string = "\n".join([f"[c]{char.character_id}[/c] (LV {char.level}) by {char.creator})" for char in chars]) char_string = "\n".join(
[f"[c]{char.character_id}[/c] (LV {char.level}) by {char.creator})" for char in chars]
)
raise CommandError(f"Multiple characters share the name {identifier}, " raise CommandError(f"Multiple characters share the name {identifier}, "
f"please activate them using their id:\n{char_string}") f"please activate them using their id:\n{char_string}")
elif len(chars) == 1: elif len(chars) == 1:
@ -45,7 +49,7 @@ class DndactiveCommand(Command):
char = None char = None
else: else:
# Find the character by id # Find the character by id
char = await asyncify(data.session.query(DndCharacterT) char = await asyncify(session.query(DndCharacterT)
.filter_by(character_id=identifier) .filter_by(character_id=identifier)
.one_or_none) .one_or_none)
if char is None: if char is None:
@ -56,11 +60,11 @@ class DndactiveCommand(Command):
achar = DndActiveCharacterT( achar = DndActiveCharacterT(
character=char, character=char,
user=author, user=author,
interface_name=self.interface.name, interface_name=data.command.serf.__class__.__name__,
interface_data=pickle.dumps(get_interface_data(data))) interface_data=pickle.dumps(get_interface_data(data)))
data.session.add(achar) session.add(achar)
else: else:
# Change the active character # Change the active character
active_character.character = char active_character.character = char
await data.session_commit() await asyncify(session.commit)
await data.reply(f"✅ Active character set to [b]{char}[/b]!") await data.reply(f"✅ Active character set to [b]{char}[/b]!")

View file

@ -18,8 +18,9 @@ class DndactivebattleCommand(Command):
BattleT = self.alchemy.get(DndBattle) BattleT = self.alchemy.get(DndBattle)
ABattleT = self.alchemy.get(DndActiveBattle) ABattleT = self.alchemy.get(DndActiveBattle)
async with data.session_acm() as session:
identifier = args.joined() identifier = args.joined()
active_battle = await get_active_battle(data) active_battle = await get_active_battle(session=session, data=data)
# Display the active character # Display the active character
if identifier == "": if identifier == "":
@ -34,7 +35,7 @@ class DndactivebattleCommand(Command):
identifier = int(identifier) identifier = int(identifier)
except ValueError: except ValueError:
# Find the battle by name # Find the battle by name
battles = await asyncify(data.session.query(BattleT).filter_by(name=identifier).all) battles = await asyncify(session.query(BattleT).filter_by(name=identifier).all)
if len(battles) >= 2: if len(battles) >= 2:
char_string = "\n".join([f"[c]{battle.id}[/c]" for battle in battles]) char_string = "\n".join([f"[c]{battle.id}[/c]" for battle in battles])
raise CommandError(f"Multiple battles share the name [b]{identifier}[/b], " raise CommandError(f"Multiple battles share the name [b]{identifier}[/b], "
@ -45,7 +46,7 @@ class DndactivebattleCommand(Command):
battle = None battle = None
else: else:
# Find the battle by id # Find the battle by id
battle = await asyncify(data.session.query(BattleT) battle = await asyncify(session.query(BattleT)
.filter_by(id=identifier) .filter_by(id=identifier)
.one_or_none) .one_or_none)
if battle is None: if battle is None:
@ -55,11 +56,11 @@ class DndactivebattleCommand(Command):
# Create a new active battle # Create a new active battle
active_battle = ABattleT( active_battle = ABattleT(
battle=battle, battle=battle,
interface_name=self.interface.name, interface_name=data.command.serf.__class__.__name__,
interface_data=pickle.dumps(get_interface_data(data))) interface_data=pickle.dumps(get_interface_data(data)))
data.session.add(active_battle) session.add(active_battle)
else: else:
# Change the active character # Change the active character
active_battle.battle = battle active_battle.battle = battle
await data.session_commit() await asyncify(session.commit)
await data.reply(f"⚔️ [b]{battle}[/b]! Roll initiative!") await data.reply(f"⚔️ [b]{battle}[/b]! Roll initiative!")

View file

@ -26,11 +26,12 @@ class DndaddunitCommand(rc.Command):
DndBattleUnitT = self.alchemy.get(DndBattleUnit) DndBattleUnitT = self.alchemy.get(DndBattleUnit)
active_battle = await get_active_battle(data) async with data.session_acm() as session:
active_battle = await get_active_battle(session=session, data=data)
if active_battle is None: if active_battle is None:
raise rc.CommandError("No battle is active in this chat.") raise rc.CommandError("No battle is active in this chat.")
units_with_same_name = await ru.asyncify(data.session.query(DndBattleUnitT).filter_by( units_with_same_name = await ru.asyncify(session.query(DndBattleUnitT).filter_by(
name=name, name=name,
battle=active_battle.battle battle=active_battle.battle
).all) ).all)
@ -53,8 +54,8 @@ class DndaddunitCommand(rc.Command):
battle=active_battle.battle battle=active_battle.battle
) )
data.session.add(dbu) session.add(dbu)
await data.session_commit() await ru.asyncify(session.commit)
await data.reply(f"{dbu}\n" await data.reply(f"{dbu}\n"
f"joins the battle!") f"joins the battle!")

View file

@ -1,5 +1,6 @@
import re import re
from royalnet.commands import * from royalnet.commands import *
import royalnet.utils as ru
from .dndnew import DndnewCommand from .dndnew import DndnewCommand
from ..tables import DndCharacter from ..tables import DndCharacter
from ..utils import get_active_character from ..utils import get_active_character
@ -15,7 +16,8 @@ class DndeditCommand(DndnewCommand):
async def run(self, args: CommandArgs, data: CommandData) -> None: async def run(self, args: CommandArgs, data: CommandData) -> None:
character_sheet = args.joined() character_sheet = args.joined()
active_character = await get_active_character(data) async with data.session_acm() as session:
active_character = await get_active_character(session=session, data=data)
if active_character is None: if active_character is None:
raise CommandError("You don't have an active character.") raise CommandError("You don't have an active character.")
@ -29,6 +31,6 @@ class DndeditCommand(DndnewCommand):
for key in arguments: for key in arguments:
char.__setattr__(key, arguments[key]) char.__setattr__(key, arguments[key])
await data.session_commit() await ru.asyncify(session.commit)
await data.reply(f"✅ Edit successful!") await data.reply(f"✅ Edit successful!")

View file

@ -20,7 +20,8 @@ class DndinfoCommand(Command):
} }
async def run(self, args: CommandArgs, data: CommandData) -> None: async def run(self, args: CommandArgs, data: CommandData) -> None:
active_character = await get_active_character(data) async with data.session_acm() as session:
active_character = await get_active_character(data=data, session=session)
if active_character is None: if active_character is None:
raise CommandError("You don't have an active character.") raise CommandError("You don't have an active character.")

View file

@ -2,6 +2,7 @@ import aiohttp
import sortedcontainers import sortedcontainers
import logging import logging
from royalnet.commands import * from royalnet.commands import *
import royalnet.serf as rs
from royalnet.utils import sentry_exc from royalnet.utils import sentry_exc
from ..utils import parse_5etools_entry from ..utils import parse_5etools_entry
@ -20,9 +21,9 @@ class DnditemCommand(Command):
_dnddata: sortedcontainers.SortedKeyList = None _dnddata: sortedcontainers.SortedKeyList = None
def __init__(self, interface: CommandInterface): def __init__(self, serf: rs.Serf, config: "ConfigDict"):
super().__init__(interface) super().__init__(serf, config)
self.loop.create_task(self._fetch_dnddata()) self.serf.tasks.add(self._fetch_dnddata())
async def _fetch_dnddata(self): async def _fetch_dnddata(self):
self._dnddata = self._dnddata = sortedcontainers.SortedKeyList([], key=lambda i: i["name"].lower()) self._dnddata = self._dnddata = sortedcontainers.SortedKeyList([], key=lambda i: i["name"].lower())

View file

@ -21,19 +21,20 @@ class DndjoinbattleCommand(rc.Command):
faction = Faction[args[0].upper()] faction = Faction[args[0].upper()]
initiative_mod = int(args.optional(1, default="0")) initiative_mod = int(args.optional(1, default="0"))
async with data.session_acm() as session:
DndBattleUnitT = self.alchemy.get(DndBattleUnit) DndBattleUnitT = self.alchemy.get(DndBattleUnit)
active_battle = await get_active_battle(data) active_battle = await get_active_battle(data=data, session=session)
if active_battle is None: if active_battle is None:
raise rc.CommandError("No battle is active in this chat.") raise rc.CommandError("No battle is active in this chat.")
active_character = await get_active_character(data) active_character = await get_active_character(data=data, session=session)
if active_character is None: if active_character is None:
raise rc.CommandError("You don't have an active character.") raise rc.CommandError("You don't have an active character.")
char: DndCharacter = active_character.character char: DndCharacter = active_character.character
units_with_same_name = await ru.asyncify(data.session.query(DndBattleUnitT).filter_by( units_with_same_name = await ru.asyncify(session.query(DndBattleUnitT).filter_by(
name=char.name, name=char.name,
battle=active_battle.battle battle=active_battle.battle
).all) ).all)
@ -56,8 +57,8 @@ class DndjoinbattleCommand(rc.Command):
battle=active_battle.battle battle=active_battle.battle
) )
data.session.add(dbu) session.add(dbu)
await data.session_commit() await ru.asyncify(session.commit)
await data.reply(f"{dbu}\n" await data.reply(f"{dbu}\n"
f"joins the battle!\n" f"joins the battle!\n"

View file

@ -1,6 +1,7 @@
import re import re
# noinspection PyUnresolvedReferences # noinspection PyUnresolvedReferences
from royalnet.commands import * from royalnet.commands import *
import royalnet.utils as ru
from ..tables import DndCharacter from ..tables import DndCharacter
from ..types import DndProficiencyType from ..types import DndProficiencyType
@ -14,7 +15,8 @@ class DndnewCommand(Command):
syntax = "{name}\n{character_sheet}" syntax = "{name}\n{character_sheet}"
def _search_value(self, name: str, string: str): @staticmethod
def _search_value(name: str, string: str):
return re.search(r"\s*" + name + r"\s*([0-9.]+)\s*", string, re.IGNORECASE) return re.search(r"\s*" + name + r"\s*([0-9.]+)\s*", string, re.IGNORECASE)
def _parse(self, character_sheet: str) -> dict: def _parse(self, character_sheet: str) -> dict:
@ -50,15 +52,16 @@ class DndnewCommand(Command):
await data.reply(self._syntax()) await data.reply(self._syntax())
return return
creator = await data.get_author() async with data.session_acm() as session:
creator = await data.find_author(session=session, required=True)
name, rest = character_sheet.split("\n", 1) name, rest = character_sheet.split("\n", 1)
character = self.alchemy.get(DndCharacter)(name=name, creator=creator, **self._parse(rest)) character = self.alchemy.get(DndCharacter)(name=name, creator=creator, **self._parse(rest))
data.session.add(character) session.add(character)
try: try:
await data.session_commit() await ru.asyncify(session.commit)
except Exception as err: except Exception as err:
# THIS IS INTENDED # THIS IS INTENDED
if err.__class__.__name__ == "IntegrityError": if err.__class__.__name__ == "IntegrityError":

View file

@ -1,6 +1,7 @@
from typing import * from typing import *
import royalnet import royalnet
import royalnet.commands as rc import royalnet.commands as rc
import royalnet.utils as ru
from ..tables import DndBattle from ..tables import DndBattle
@ -18,12 +19,13 @@ class DndnewbattleCommand(rc.Command):
name = line_args[0] name = line_args[0]
description = line_args[1] if len(line_args) > 1 else None description = line_args[1] if len(line_args) > 1 else None
async with data.session_acm() as session:
battle = BattleT( battle = BattleT(
name=name, name=name,
description=description description=description
) )
data.session.add(battle) session.add(battle)
await data.session_commit() await ru.asyncify(session.commit)
await data.reply(f"✅ Battle [b]{battle.name}[/b] (ID: {battle.id}) created!") await data.reply(f"✅ Battle [b]{battle.name}[/b] (ID: {battle.id}) created!")

View file

@ -78,7 +78,8 @@ class DndrollCommand(Command):
} }
async def run(self, args: CommandArgs, data: CommandData) -> None: async def run(self, args: CommandArgs, data: CommandData) -> None:
active_character = await get_active_character(data) async with data.session_acm() as session:
active_character = await get_active_character(session=session, data=data)
if active_character is None: if active_character is None:
raise CommandError("You don't have an active character.") raise CommandError("You don't have an active character.")
char = active_character.character char = active_character.character
@ -131,14 +132,14 @@ class DndrollCommand(Command):
roll_b = random.randrange(1, 21) roll_b = random.randrange(1, 21)
roll = max([roll_a, roll_b]) roll = max([roll_a, roll_b])
total = roll + modifier total = roll + modifier
await data.reply(f"🎲 2d20h1{modifier_str} = ({roll_a}|{roll_b}){modifier_str} = [b]{total}[/b]") await data.reply(f"🎲 [i]{skill_name.capitalize()}[/i]: 2d20h1{modifier_str} = ({roll_a}|{roll_b} ){modifier_str} = [b]{total}[/b]")
elif disadvantage: elif disadvantage:
roll_a = random.randrange(1, 21) roll_a = random.randrange(1, 21)
roll_b = random.randrange(1, 21) roll_b = random.randrange(1, 21)
roll = min([roll_a, roll_b]) roll = min([roll_a, roll_b])
total = roll + modifier total = roll + modifier
await data.reply(f"🎲 2d20l1{modifier_str} = ({roll_a}|{roll_b}){modifier_str} = [b]{total}[/b]") await data.reply(f"🎲 [i]{skill_name.capitalize()}[/i]: 2d20l1{modifier_str} = ({roll_a}|{roll_b}){modifier_str} = [b]{total}[/b]")
else: else:
roll = random.randrange(1, 21) roll = random.randrange(1, 21)
total = roll + modifier total = roll + modifier
await data.reply(f"🎲 1d20{modifier_str} = {roll}{modifier_str} = [b]{total}[/b]") await data.reply(f"🎲 [i]{skill_name.capitalize()}[/i]: 1d20{modifier_str} = {roll}{modifier_str} = [b]{total}[/b]")

View file

@ -3,6 +3,7 @@ import sortedcontainers
import logging import logging
from royalnet.commands import * from royalnet.commands import *
from royalnet.utils import ordinalformat, andformat, sentry_exc from royalnet.utils import ordinalformat, andformat, sentry_exc
import royalnet.serf as rs
from ..utils import parse_5etools_entry from ..utils import parse_5etools_entry
@ -20,9 +21,9 @@ class DndspellCommand(Command):
_dnddata: sortedcontainers.SortedKeyList = None _dnddata: sortedcontainers.SortedKeyList = None
def __init__(self, interface: CommandInterface): def __init__(self, serf: rs.Serf, config: "ConfigDict"):
super().__init__(interface) super().__init__(serf, config)
interface.loop.create_task(self._fetch_dnddata()) self.serf.tasks.add(self._fetch_dnddata())
async def _fetch_dnddata(self): async def _fetch_dnddata(self):
self._dnddata = self._dnddata = sortedcontainers.SortedKeyList([], key=lambda i: i["name"].lower()) self._dnddata = self._dnddata = sortedcontainers.SortedKeyList([], key=lambda i: i["name"].lower())

View file

@ -28,7 +28,7 @@ class RollCommand(Command):
except ValueError: except ValueError:
if isinstance(first, str) and "d20" in first: if isinstance(first, str) and "d20" in first:
raise InvalidInputError(f"Invalid value specified.\n" raise InvalidInputError(f"Invalid value specified.\n"
f"Were you looking for [c]{self.interface.prefix}dice[/c]?") f"Were you looking for [c]{self.serf.prefix}dice[/c]?")
else: else:
raise InvalidInputError("Invalid value specified.") raise InvalidInputError("Invalid value specified.")
result = random.randrange(minimum, maximum+1) result = random.randrange(minimum, maximum+1)

View file

@ -6,26 +6,25 @@ import royalnet.commands as rc
import pickle import pickle
async def get_active_battle(data: rc.CommandData) -> Optional[DndActiveBattle]: async def get_active_battle(*, data: rc.CommandData, session) -> Optional[DndActiveBattle]:
interface = data._interface alchemy = data.alchemy
alchemy = interface.alchemy
idata = get_interface_data(data) idata = get_interface_data(data)
DndAcBaT = alchemy.get(DndActiveBattle) DndAcBaT = alchemy.get(DndActiveBattle)
active_battles: List[DndActiveBattle] = await ru.asyncify( active_battles: List[DndActiveBattle] = await ru.asyncify(
data.session session
.query(DndAcBaT) .query(DndAcBaT)
.filter_by(interface_name=interface.name) .filter_by(interface_name=data.command.serf.__class__.__name__)
.all .all
) )
for active_battle in active_battles: for active_battle in active_battles:
if interface.name == "telegram": if data.command.serf.__class__.__name__ == "TelegramSerf":
# interface_data is chat id # interface_data is chat id
chat_id = pickle.loads(active_battle.interface_data) chat_id = pickle.loads(active_battle.interface_data)
if chat_id == idata: if chat_id == idata:
return active_battle return active_battle
elif interface.name == "discord": elif data.command.serf.__class__.__name__ == "DiscordSerf":
# interface_data is channel id # interface_data is channel id
chat_id = pickle.loads(active_battle.interface_data) chat_id = pickle.loads(active_battle.interface_data)
if chat_id == idata: if chat_id == idata:

View file

@ -6,27 +6,26 @@ import royalnet.commands as rc
import pickle import pickle
async def get_active_character(data: rc.CommandData) -> Optional[DndActiveCharacter]: async def get_active_character(*, data: rc.CommandData, session) -> Optional[DndActiveCharacter]:
interface = data._interface alchemy = data.alchemy
alchemy = interface.alchemy user = await data.find_author(session=session, required=True)
user = await data.get_author(error_if_none=True)
idata = get_interface_data(data) idata = get_interface_data(data)
DndAcChT = alchemy.get(DndActiveCharacter) DndAcChT = alchemy.get(DndActiveCharacter)
active_characters: List[DndActiveCharacter] = await ru.asyncify( active_characters: List[DndActiveCharacter] = await ru.asyncify(
data.session session
.query(DndAcChT) .query(DndAcChT)
.filter_by(interface_name=interface.name, user=user) .filter_by(interface_name=data.command.serf.__class__.__name__, user=user)
.all .all
) )
for active_character in active_characters: for active_character in active_characters:
if interface.name == "telegram": if data.command.serf.__class__.__name__ == "TelegramSerf":
# interface_data is chat id # interface_data is chat id
chat_id = pickle.loads(active_character.interface_data) chat_id = pickle.loads(active_character.interface_data)
if chat_id == idata: if chat_id == idata:
return active_character return active_character
elif interface.name == "discord": elif data.command.serf.__class__.__name__ == "DiscordSerf":
# interface_data is channel id # interface_data is channel id
chat_id = pickle.loads(active_character.interface_data) chat_id = pickle.loads(active_character.interface_data)
if chat_id == idata: if chat_id == idata:

View file

@ -2,9 +2,9 @@ import royalnet.commands as rc
def get_interface_data(data: rc.CommandData): def get_interface_data(data: rc.CommandData):
if data._interface.name == "telegram": if data.command.serf.__class__.__name__ == "TelegramSerf":
return data.message.chat.id return data.message.chat.id
elif data._interface.name == "discord": if data.command.serf.__class__.__name__ == "DiscordSerf":
return data.message.channel.id return data.message.channel.id
else: else:
raise rc.UnsupportedError("This interface isn't supported yet.") raise rc.UnsupportedError("This interface isn't supported yet.")

View file

@ -8,8 +8,8 @@ from ..types.faction import Faction
from sqlalchemy import and_ from sqlalchemy import and_
async def get_targets(data: rc.CommandData, target: Optional[str]) -> List[DndBattleUnit]: async def get_targets(target: Optional[str], *, data: rc.CommandData, session) -> List[DndBattleUnit]:
DndBattleUnitT = data._interface.alchemy.get(DndBattleUnit) DndBattleUnitT = data.alchemy.get(DndBattleUnit)
active_battle = await get_active_battle(data) active_battle = await get_active_battle(data)
if active_battle is None: if active_battle is None:
@ -23,14 +23,14 @@ async def get_targets(data: rc.CommandData, target: Optional[str]) -> List[DndBa
return [] return []
char = active_character.character char = active_character.character
return await ru.asyncify(data.session.query(DndBattleUnitT).filter_by( return await ru.asyncify(session.query(DndBattleUnitT).filter_by(
linked_character=char, linked_character=char,
battle=battle battle=battle
).all) ).all)
# Get all # Get all
if target.upper() == "ALL": if target.upper() == "ALL":
return await ru.asyncify(data.session.query(DndBattleUnitT).filter_by( return await ru.asyncify(session.query(DndBattleUnitT).filter_by(
battle=battle battle=battle
).all) ).all)
@ -40,13 +40,13 @@ async def get_targets(data: rc.CommandData, target: Optional[str]) -> List[DndBa
except ValueError: except ValueError:
pass pass
else: else:
return await ru.asyncify(data.session.query(DndBattleUnitT).filter_by( return await ru.asyncify(session.query(DndBattleUnitT).filter_by(
faction=faction, faction=faction,
battle=battle battle=battle
).all) ).all)
# Get by ilike # Get by ilike
return await ru.asyncify(data.session.query(DndBattleUnitT).filter(and_( return await ru.asyncify(session.query(DndBattleUnitT).filter(and_(
DndBattleUnitT.name.ilike(target), DndBattleUnitT.name.ilike(target),
DndBattleUnitT.battle == battle DndBattleUnitT.battle == battle
)).all) )).all)