async def _approve(self, template): await self.client.db.templates.update_one({"_id": template["_id"]}, {"$set": { "approved": True }}) template["approved"] = True dm_channel = await self.client.start_dm( wkr.Snowflake(template["creator"])) await self.client.f_send( dm_channel, f"Your **template `{template['_id']}` got approved**.", f=self.client.f.INFO) await self.client.f_send(wkr.Snowflake(self.LIST_CHANNEL), embed=self._template_info(template))
async def on_message_reaction_add(self, shard_id, data): if data["channel_id"] != self.APPROVAL_CHANNEL or data[ "user_id"] == self.bot.user.id: return action = self.APPROVAL_OPTIONS.get(data["emoji"]["name"]) if action is None: return try: msg = await self.client.fetch_message( wkr.Snowflake(data["channel_id"]), data["message_id"]) except wkr.NotFound: return if len(msg.embeds) == 0: return tpl_name = msg.embeds[0].get("title", "").strip(" ✅❌") if tpl_name == "": return template = await self.client.db.templates.find_one({"_id": tpl_name}) if template is not None: await action(template) await self.client.delete_message(msg)
async def predicate(template): await self.client.db.templates.delete_one({"_id": template["_id"]}) dm_channel = await self.client.start_dm( wkr.Snowflake(template["creator"])) await self.client.f_send( dm_channel, f"Your **template `{template['_id']}` got denied**.```\n{reason}\n```", f=self.client.f.INFO)
async def _load_bans(self): for ban in self.data.get("bans", []): try: await self.client.ban_user(self.guild, wkr.Snowflake(ban["id"]), reason=ban["reason"]) except Exception: pass
async def _load_bans(self): self.status = "loading bans" for ban in self.data.get("bans", []): try: await self.client.ban_user(self.guild, wkr.Snowflake(ban["id"]), reason=ban["reason"]) except wkr.DiscordException: pass
async def role(self, ctx, role_id, server_id=None): if not await ctx.bot.redis.hexists("roles", role_id): if server_id is None: raise ctx.f.ERROR("Role is not in cache. Provide a server_id to fetch and add it.") await ctx.f_send("Role is not in cache. Fetching and adding ...", f=ctx.f.WORKING) try: roles = await ctx.bot.fetch_roles(wkr.Snowflake(server_id)) await ctx.bot.redis.hmset_dict("roles", {r.id: msgpack.packb(r.to_dict()) for r in roles}) except wkr.NotFound: raise ctx.f.ERROR("Role not found.") result = await ctx.bot.redis.hget("roles", role_id) data = msgpack.unpackb(result) raise ctx.f.INFO(f"```js\n{json.dumps(data, indent=1)}\n```")
async def leave(self, ctx): """ Let the bot leave this guild """ await ctx.send("bye ;(") await ctx.bot.leave_guild(wkr.Snowflake(ctx.guild_id))
async def _send_to_approval(self, template): msg = await self.client.f_send(wkr.Snowflake(self.APPROVAL_CHANNEL), embed=self._template_info(template)) for option in self.APPROVAL_OPTIONS.keys(): await self.client.add_reaction(msg, option)