diff --git a/ygo/deck_editor.py b/ygo/deck_editor.py index 6f64596..1727770 100644 --- a/ygo/deck_editor.py +++ b/ygo/deck_editor.py @@ -98,9 +98,9 @@ def list_decks(self, selector = DECK.OWNED, name = '', banlist = ''): other_decks = decks - public_decks = natsort.natsorted(public_decks, key = lambda d: d.account.name + "/" + d.name) - owned_decks = natsort.natsorted(owned_decks, key = lambda d: d.name) - other_decks = natsort.natsorted(other_decks, key = lambda d: d.account.name + "/" + d.name) + public_decks = natsort.natsorted(public_decks, key = lambda d: str(d.id) + ": " + d.account.name + "/" + d.name) + owned_decks = natsort.natsorted(owned_decks, key = lambda d: str(d.id) + ": " + d.name) + other_decks = natsort.natsorted(other_decks, key = lambda d: str(d.id) + ": " + d.account.name + "/" + d.name) if len(public_decks): @@ -119,7 +119,7 @@ def list_decks(self, selector = DECK.OWNED, name = '', banlist = ''): banlist_text = pl._("compatible with {0} banlist").format(b.name) break - pl.notify(pl._("{deckname} ({banlist})").format(deckname=deck.account.name + "/" + deck.name, banlist=banlist_text)) + pl.notify(pl._("{deck_id}: {deckname} ({banlist})").format(deck_id=deck.id, deckname=deck.account.name + "/" + deck.name, banlist=banlist_text)) if len(owned_decks): @@ -143,7 +143,7 @@ def list_decks(self, selector = DECK.OWNED, name = '', banlist = ''): banlist_text = pl._("compatible with {0} banlist").format(b.name) break - pl.notify(pl._("{deckname} ({privacy}) ({banlist})").format(deckname=deck.name, privacy=privacy, banlist=banlist_text)) + pl.notify(pl._("{deck_id}: {deckname} ({privacy}) ({banlist})").format(deck_id=deck.id, deckname=deck.name, privacy=privacy, banlist=banlist_text)) if len(other_decks): diff --git a/ygo/models.py b/ygo/models.py index 396d33b..c13eb04 100644 --- a/ygo/models.py +++ b/ygo/models.py @@ -69,6 +69,14 @@ def find(session, account, name): def find_public(session, account, name): return session.query(Deck).filter_by(account_id=account.id, name=name, public = True).first() + @staticmethod + def find_by_id(session, account, id): + return session.query(Deck).filter_by(account_id=account.id, id=id).first() + + @staticmethod + def find_public_by_id(session, id): + return session.query(Deck).filter_by(id=id, public = True).first() + class Ignore(Base): __tablename__ = 'ignores' account_id = Column(Integer, ForeignKey('accounts.id'), nullable=False) diff --git a/ygo/parsers/room_parser.py b/ygo/parsers/room_parser.py index d9dab07..ee9b4cb 100644 --- a/ygo/parsers/room_parser.py +++ b/ygo/parsers/room_parser.py @@ -238,6 +238,19 @@ def deck(caller): player_name = '' deck_name = name + deck = None + # if deck_name only contains a number, it's a deck id + if deck_name.isdigit(): + # first try to find in our own decks + deck = models.Deck.find_by_id(session, account, int(deck_name)) + if not deck: + # if not found, try to find in public decks + deck = models.Deck.find_public_by_id(session, int(deck_name)) + # if deck is still None, it means that the deck doesn't exist + if deck is None: + pl.notify(pl._("Deck doesn't exist or isn't publically available.")) + return + if '/' in deck_name: player_name = deck_name.split("/")[0].title() deck_name = deck_name[(len(player_name) + 1):] @@ -256,7 +269,8 @@ def deck(caller): deck = models.Deck.find(session, account, deck_name) - else: + # and if the deck is alphanumeric, it's a deck name + if deck_name.isalnum() and not deck: # if deck is a name and still hasn't been found deck = models.Deck.find(session, account, deck_name) @@ -312,7 +326,7 @@ def deck(caller): return pl.deck = content - pl.notify(pl._("Deck loaded with %d cards.") % len(content['cards'])) + pl.notify(pl._("Deck %s loaded with %d cards.") % (deck.name, len(content['cards']))) for p in room.get_all_players(): if p is not pl: