Skip to content

Commit

Permalink
Add tag count in embed footer
Browse files Browse the repository at this point in the history
  • Loading branch information
WitherredAway committed Jan 25, 2025
1 parent f4be81c commit 7f1af3e
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions cogs/tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,14 @@ async def query_tags(self, query, sort=True):
async for tag_data in tags:
yield Tag(**tag_data)

async def send_tags(self, ctx, tags):
async def count_tags(self, query):
return await self.bot.mongo.db.tag.count_documents(query)

async def send_tags(self, ctx, tags, *, count: int = None):
pages = ViewMenuPages(
source=AsyncEmbedListPageSource(
tags,
count=count,
show_index=True,
format_item=lambda x: x.name,
)
Expand Down Expand Up @@ -148,21 +152,25 @@ async def raw(self, ctx, *, name):
async def all(self, ctx):
"""Lists all tags."""

await self.send_tags(ctx, self.query_tags({}))
query = {}
await self.send_tags(ctx, self.query_tags(query), count=await self.count_tags(query))

@tag.command()
async def search(self, ctx, *, text):
"""Searches for a tag."""

await self.send_tags(ctx, self.query_tags({"$text": {"$search": text}}, sort=False))
query = {"$text": {"$search": text}}
await self.send_tags(ctx, self.query_tags(query, sort=False), count=await self.count_tags(query))

@tag.command()
async def list(self, ctx, *, member: discord.Member = None):
"""Lists all the tags that belong to you or someone else."""

if member is None:
member = ctx.author
await self.send_tags(ctx, self.query_tags({"owner_id": member.id}))

query = {"owner_id": member.id}
await self.send_tags(ctx, self.query_tags(query), count=await self.count_tags(query))

# Writing tags

Expand Down

0 comments on commit 7f1af3e

Please sign in to comment.