From 1066b3f0d385f7b6abc85ffe65c478ab6e07d8f6 Mon Sep 17 00:00:00 2001 From: JessicaTegner Date: Thu, 30 Mar 2023 01:06:22 +0200 Subject: [PATCH 01/11] Trying to print id as well --- ygo/deck_editor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ygo/deck_editor.py b/ygo/deck_editor.py index 6f64596..976d58f 100644 --- a/ygo/deck_editor.py +++ b/ygo/deck_editor.py @@ -98,7 +98,7 @@ 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) + public_decks = natsort.natsorted(public_decks, key = lambda d: d.id + ": " + 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) From 554c018d2ccf7224ef91685f83337f6c28c0fb64 Mon Sep 17 00:00:00 2001 From: JessicaTegner Date: Thu, 30 Mar 2023 01:10:03 +0200 Subject: [PATCH 02/11] More ids --- ygo/deck_editor.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ygo/deck_editor.py b/ygo/deck_editor.py index 976d58f..0bf7981 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.id + ": " + 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): From dcebb8a4756685b235684e5aafcfd54c94ef43af Mon Sep 17 00:00:00 2001 From: JessicaTegner Date: Thu, 30 Mar 2023 01:15:48 +0200 Subject: [PATCH 03/11] Updating notify code --- ygo/deck_editor.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ygo/deck_editor.py b/ygo/deck_editor.py index 0bf7981..1727770 100644 --- a/ygo/deck_editor.py +++ b/ygo/deck_editor.py @@ -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): From 93868589631ae2643ae516d44feb26cf0b3d7be5 Mon Sep 17 00:00:00 2001 From: JessicaTegner Date: Thu, 30 Mar 2023 01:28:22 +0200 Subject: [PATCH 04/11] Updated deck command --- ygo/models.py | 8 ++++++++ ygo/parsers/room_parser.py | 16 +++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/ygo/models.py b/ygo/models.py index 396d33b..939fdf2 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, account, id): + return session.query(Deck).filter_by(account_id=account.id, 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..59e8fe3 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 not deck: + 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(): deck = models.Deck.find(session, account, deck_name) From 351ef8050b3348e475a1bb30cd781c81ecdd1615 Mon Sep 17 00:00:00 2001 From: JessicaTegner Date: Thu, 30 Mar 2023 01:33:17 +0200 Subject: [PATCH 05/11] Debug --- ygo/models.py | 5 +++-- ygo/parsers/room_parser.py | 3 +++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/ygo/models.py b/ygo/models.py index 939fdf2..1d0f832 100644 --- a/ygo/models.py +++ b/ygo/models.py @@ -71,11 +71,12 @@ def find_public(session, account, name): @staticmethod def find_by_id(session, account, id): + print(f"find_by_id: {id}") return session.query(Deck).filter_by(account_id=account.id, id=id).first() @staticmethod - def find_public_by_id(session, account, id): - return session.query(Deck).filter_by(account_id=account.id, id=id, public = True).first() + def find_public_by_id(session, id): + return session.query(Deck).filter_by(id=id, public = True).first() class Ignore(Base): __tablename__ = 'ignores' diff --git a/ygo/parsers/room_parser.py b/ygo/parsers/room_parser.py index 59e8fe3..0d7bd76 100644 --- a/ygo/parsers/room_parser.py +++ b/ygo/parsers/room_parser.py @@ -241,11 +241,14 @@ def deck(caller): deck = None # if deck_name only contains a number, it's a deck id if deck_name.isdigit(): + print("deck_name is a number") # first try to find in our own decks deck = models.Deck.find_by_id(session, account, int(deck_name)) + print("deck is %s" % deck) if not deck: # if not found, try to find in public decks deck = models.Deck.find_public_by_id(session, int(deck_name)) + print("deck is %s" % deck) # if deck is still None, it means that the deck doesn't exist if not deck: pl.notify(pl._("Deck doesn't exist or isn't publically available.")) From 92613e7c43e8cfcca65e6329cbb591bbb6259cfb Mon Sep 17 00:00:00 2001 From: JessicaTegner Date: Thu, 30 Mar 2023 01:35:38 +0200 Subject: [PATCH 06/11] Change debug statement --- ygo/parsers/room_parser.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ygo/parsers/room_parser.py b/ygo/parsers/room_parser.py index 0d7bd76..2feeb04 100644 --- a/ygo/parsers/room_parser.py +++ b/ygo/parsers/room_parser.py @@ -241,14 +241,14 @@ def deck(caller): deck = None # if deck_name only contains a number, it's a deck id if deck_name.isdigit(): - print("deck_name is a number") + pl.notify("deck_name is a number") # first try to find in our own decks deck = models.Deck.find_by_id(session, account, int(deck_name)) - print("deck is %s" % deck) + pl.notify("deck is %s" % deck) if not deck: # if not found, try to find in public decks deck = models.Deck.find_public_by_id(session, int(deck_name)) - print("deck is %s" % deck) + pl.notify("deck is %s" % deck) # if deck is still None, it means that the deck doesn't exist if not deck: pl.notify(pl._("Deck doesn't exist or isn't publically available.")) From e89cb052db250e586447261478e672c03bc64caa Mon Sep 17 00:00:00 2001 From: JessicaTegner Date: Thu, 30 Mar 2023 01:40:03 +0200 Subject: [PATCH 07/11] more error checking --- ygo/parsers/room_parser.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ygo/parsers/room_parser.py b/ygo/parsers/room_parser.py index 2feeb04..a32f1a2 100644 --- a/ygo/parsers/room_parser.py +++ b/ygo/parsers/room_parser.py @@ -250,7 +250,7 @@ def deck(caller): deck = models.Deck.find_public_by_id(session, int(deck_name)) pl.notify("deck is %s" % deck) # if deck is still None, it means that the deck doesn't exist - if not deck: + if deck is None: pl.notify(pl._("Deck doesn't exist or isn't publically available.")) return @@ -273,7 +273,7 @@ def deck(caller): deck = models.Deck.find(session, account, deck_name) # and if the deck is alphanumeric, it's a deck name - if deck_name.isalnum(): + if deck_name.isalnum() and not deck: # if deck is a name and still hasn't be found deck = models.Deck.find(session, account, deck_name) From 14825283c540dbf2ee65a539fa2126ff2f4694f4 Mon Sep 17 00:00:00 2001 From: JessicaTegner Date: Thu, 30 Mar 2023 01:41:19 +0200 Subject: [PATCH 08/11] Removed debug statements --- ygo/models.py | 1 - ygo/parsers/room_parser.py | 3 --- 2 files changed, 4 deletions(-) diff --git a/ygo/models.py b/ygo/models.py index 1d0f832..c13eb04 100644 --- a/ygo/models.py +++ b/ygo/models.py @@ -71,7 +71,6 @@ def find_public(session, account, name): @staticmethod def find_by_id(session, account, id): - print(f"find_by_id: {id}") return session.query(Deck).filter_by(account_id=account.id, id=id).first() @staticmethod diff --git a/ygo/parsers/room_parser.py b/ygo/parsers/room_parser.py index a32f1a2..d7f25f7 100644 --- a/ygo/parsers/room_parser.py +++ b/ygo/parsers/room_parser.py @@ -241,14 +241,11 @@ def deck(caller): deck = None # if deck_name only contains a number, it's a deck id if deck_name.isdigit(): - pl.notify("deck_name is a number") # first try to find in our own decks deck = models.Deck.find_by_id(session, account, int(deck_name)) - pl.notify("deck is %s" % deck) if not deck: # if not found, try to find in public decks deck = models.Deck.find_public_by_id(session, int(deck_name)) - pl.notify("deck is %s" % deck) # 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.")) From 77e4edf352f6c19fb89ac304d112fa67bc9de74c Mon Sep 17 00:00:00 2001 From: JessicaTegner Date: Thu, 30 Mar 2023 01:47:55 +0200 Subject: [PATCH 09/11] Added deck name in load message --- ygo/parsers/room_parser.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ygo/parsers/room_parser.py b/ygo/parsers/room_parser.py index d7f25f7..666c92c 100644 --- a/ygo/parsers/room_parser.py +++ b/ygo/parsers/room_parser.py @@ -326,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: From 19dd683a9c0484236c27cfb4a90988ffc03d93fb Mon Sep 17 00:00:00 2001 From: JessicaTegner Date: Thu, 30 Mar 2023 01:50:37 +0200 Subject: [PATCH 10/11] fixed small error with format string --- ygo/parsers/room_parser.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ygo/parsers/room_parser.py b/ygo/parsers/room_parser.py index 666c92c..89ffc0f 100644 --- a/ygo/parsers/room_parser.py +++ b/ygo/parsers/room_parser.py @@ -326,7 +326,7 @@ def deck(caller): return pl.deck = content - pl.notify(pl._("Deck %s loaded with %d cards.") % deck.name, 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: From ceecbee20659e1cd4ad1289ab18135e6309b15b6 Mon Sep 17 00:00:00 2001 From: JessicaTegner Date: Thu, 30 Mar 2023 01:52:57 +0200 Subject: [PATCH 11/11] Updated typo in comment --- ygo/parsers/room_parser.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ygo/parsers/room_parser.py b/ygo/parsers/room_parser.py index 89ffc0f..ee9b4cb 100644 --- a/ygo/parsers/room_parser.py +++ b/ygo/parsers/room_parser.py @@ -270,7 +270,7 @@ def deck(caller): deck = models.Deck.find(session, account, deck_name) # 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 be found + 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)