async def list(self, ctx): """ Get a list of your backups __Examples__ ```{c.prefix}backup list``` """ args = { "limit": 10, "skip": 0, "sort": [("timestamp", pymongo.DESCENDING)], "filter": { "creator": ctx.author.id, } } msg = await ctx.send(embed=await self.create_list(args)) options = ["◀", "❎", "▶"] for option in options: await msg.add_reaction(option) try: async for reaction, user in helpers.IterWaitFor( self.bot, event="reaction_add", check=lambda r, u: u.id == ctx.author.id and r.message.id == msg.id and str(r.emoji) in options, timeout=60): emoji = reaction.emoji if isinstance(ctx.channel, TextChannel): try: await msg.remove_reaction(emoji, user) except Exception: pass if str(emoji) == options[0]: if args["skip"] > 0: args["skip"] -= args["limit"] await msg.edit(embed=await self.create_list(args)) elif str(emoji) == options[2]: args["skip"] += args["limit"] await msg.edit(embed=await self.create_list(args)) else: raise TimeoutError except TimeoutError: if isinstance(ctx.channel, TextChannel): try: await msg.clear_reactions() except Exception: pass
async def run(self): self.msg = await self.ctx.send(embed=self._create_embed()) options = { **{f"{i + 1}\u20e3": self._switch_option(i) for i in range(9)}, "◀": self._prev_page, "▶": self._next_page, "❎": self._cancel, "✅": self._finish, } for option in options: await self.msg.add_reaction(option) try: async for reaction, user in helpers.IterWaitFor( self.ctx.bot, event="reaction_add", check=lambda r, u: u.id == self.ctx.author.id and r.message .id == self.msg.id and str(r.emoji) in options.keys(), timeout=3 * 60): self.ctx.bot.loop.create_task( self.msg.remove_reaction(reaction.emoji, user)) if not await options[str(reaction.emoji)](): try: await self.msg.clear_reactions() except Exception: pass return { name: value for page in self.pages for name, value in page["options"] } await self.update() except asyncio.TimeoutError: try: await self.msg.clear_reactions() except Exception: pass raise cmd.CommandError( "**Canceled build process**, because you didn't do anything.")
async def query(self, expression, timeout=0.5): nonce = str(uuid.uuid4()) await self.redis.publish_json("shards", { "t": "q", "a": self.shard_ids, "d": {"n": nonce, "e": expression} }) responses = [] try: async for author, data in helpers.IterWaitFor( self, event="query_response", check=lambda a, d: d["n"] == nonce, timeout=timeout ): responses.append((author, data["r"])) except asyncio.TimeoutError: pass return responses
async def list(self, ctx, *, keywords=""): """ Get a list of public templates __Arguments__ **keywords**: Keywords to search for. Make sure to include non stop-words __Examples__ List all backups: ```{c.prefix}template list``` Search for a template: ```{c.prefix}template search basic``` """ # await ctx.db.templates.create_index([("description", pymongo.TEXT), ("_id", pymongo.TEXT)]) args = { "limit": 10, "skip": 0, "sort": [("featured", pymongo.DESCENDING), ("used", pymongo.DESCENDING)], "filter": { "approved": True, } } if len(keywords) != 0: args["filter"]["$text"] = { "$search": keywords, "$caseSensitive": False } msg = await ctx.send(embed=await self.create_list(args)) options = ["◀", "❎", "▶"] for option in options: await msg.add_reaction(option) try: async for reaction, user in helpers.IterWaitFor( self.bot, event="reaction_add", check=lambda r, u: u.id == ctx.author.id and r.message.id == msg.id and str(r.emoji) in options, timeout=60): emoji = reaction.emoji if isinstance(ctx.channel, discord.TextChannel): try: await msg.remove_reaction(emoji, user) except Exception: pass if str(emoji) == options[0]: if args["skip"] > 0: args["skip"] -= args["limit"] await msg.edit(embed=await self.create_list(args)) elif str(emoji) == options[2]: args["skip"] += args["limit"] await msg.edit(embed=await self.create_list(args)) else: raise TimeoutError except TimeoutError: if isinstance(ctx.channel, discord.TextChannel): try: await msg.clear_reactions() except Exception: pass