Skip to content

Commit

Permalink
Fix pokemon querying
Browse files Browse the repository at this point in the history
  • Loading branch information
oliver-ni committed Dec 4, 2021
1 parent d3db56f commit ba3e5de
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
17 changes: 12 additions & 5 deletions cogs/mongo.py
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ async def fetch_auction_count(self, guild, aggregations=[]):

async def fetch_pokemon_list(self, member: discord.Member, aggregations=[]):
pipeline = [
{"$match": {"owner_id": member.id, "owned_by": "user"}},
{"$match": {"owner_id": member.id, "owned_by": {"$nin": ["market", "released"]}}},
*aggregations,
]
print(pipeline)
Expand All @@ -515,7 +515,7 @@ async def fetch_pokemon_list(self, member: discord.Member, aggregations=[]):
async def fetch_pokemon_count(self, member: discord.Member, aggregations=[]):
result = await self.db.pokemon.aggregate(
[
{"$match": {"owner_id": member.id, "owned_by": "user"}},
{"$match": {"owner_id": member.id, "owned_by": {"$nin": ["market", "released"]}}},
*aggregations,
{"$count": "num_matches"},
],
Expand Down Expand Up @@ -583,11 +583,18 @@ async def update_pokemon(self, pokemon, update):

async def fetch_pokemon(self, member: discord.Member, idx: int):
if isinstance(idx, ObjectId):
result = await self.db.pokemon.find_one({"_id": idx, "owned_by": "user"})
result = await self.db.pokemon.find_one(
{"_id": idx, "owned_by": {"$nin": ["market", "released"]}}
)
elif idx == -1:
result = await self.db.pokemon.aggregate(
[
{"$match": {"owner_id": member.id, "owned_by": "user"}},
{
"$match": {
"owner_id": member.id,
"owned_by": {"$nin": ["market", "released"]},
}
},
{"$sort": {"idx": -1}},
{"$limit": 1},
],
Expand All @@ -600,7 +607,7 @@ async def fetch_pokemon(self, member: discord.Member, idx: int):
result = result[0]
else:
result = await self.db.pokemon.find_one(
{"owner_id": member.id, "idx": idx, "owned_by": "user"}
{"owner_id": member.id, "idx": idx, "owned_by": {"$nin": ["market", "released"]}}
)

if result is None:
Expand Down
6 changes: 3 additions & 3 deletions cogs/pokemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ async def reindex(self, ctx):

num = await self.bot.mongo.fetch_pokemon_count(ctx.author)
await self.bot.mongo.reset_idx(ctx.author, value=num + 1)
mons = self.bot.mongo.db.pokemon.find({"owner_id": ctx.author.id, "owned_by": "user"}).sort(
"idx"
)
mons = self.bot.mongo.db.pokemon.find(
{"owner_id": ctx.author.id, "owned_by": {"$nin": ["market", "released"]}}
).sort("idx")

ops = []

Expand Down

0 comments on commit ba3e5de

Please sign in to comment.