async def on_raw_reaction_remove(struct: discord.RawReactionActionEvent): if struct.guild_id is None: return None # ignorar DMs async with create_async_database("main.db") as wrap: fields = ( Field(name="channel", type="TEXT"), Field(name="message", type="TEXT"), Field(name="emoji", type="TEXT"), Field(name="role", type="TEXT") ) await wrap.create_table_if_absent("reaction_roles", fields) item = await wrap.get_item("reaction_roles", where=f"message = {struct.message_id}") if item is not None: try: channel_id, message_id, emoji, role_id = item[0] except IndexError: return guild = client.get_guild(struct.guild_id) channel = guild.get_channel(struct.channel_id) member = guild.get_member(struct.user_id) role = guild.get_role(role_id) if emoji == str(struct.emoji) and message_id == struct.message_id: await member.remove_roles(role, reason="Reaction Roles.", atomic=True)
async def blacklist(ctx): fields = ( Field(name="user_id", type="TEXT NOT NULL"), Field(name="reason", type="TEXT") ) async with create_async_database("main.db") as wrap: await wrap.create_table_if_absent("blacklisteds", fields) item = await wrap.get_item("blacklisteds", f"user_id = {ctx.author.id}", 'user_id') if item is None: return True raise UserBlacklisted
async def whitelist(self, ctx, user: Union[discord.Member, discord.User]): """ Tira um usuário da lista negra. **Veja também**: Comando `blacklist`. """ async with create_async_database("main.db") as wrap: item = await wrap.get_item("blacklisteds", f"user_id = {user.id}", "user_id") if item is None: return await ctx.reply(f"O usuário {user} não está banido.") await wrap.remove_item("blacklisteds", f"user_id = {user.id}") await ctx.reply(f"O usuário {user} foi desbanido.")
async def setchannel(ctx, channel: Optional[discord.TextChannel]): """Define o canal padrão para as respostas principais (logs). Você precisa da permissão `Gerenciar Canais`. """ if channel is None: channel = ctx.channel async with create_async_database("main.db") as db: fields = ( Field(name="guild", type="TEXT NOT NULL"), Field(name="channel", type="TEXT NOT NULL") ) await db.create_table_if_absent("default_channels", fields=fields) db._cursor.execute("INSERT INTO default_channels(guild, channel) VALUES (?,?)", (ctx.guild.id, ctx.channel.id)) db._connection.commit() await ctx.channel.send(embed=discord.Embed( description='Canal {} adicionado como canal principal de respostas!'.format(channel.mention), color=0xff0000))
async def on_command_error(ctx, error): if isinstance(error, commands.CommandOnCooldown): await ctx.send( f"{ctx.author.mention} Pare. Pare imediatamente de executar este comando. Ainda faltam {int(round(error.retry_after, 0))}s para você " "usar o comando novamente.", delete_after=error.retry_after ) await asyncio.sleep(error.retry_after) await ctx.message.delete() elif isinstance(error, commands.MemberNotFound): await ctx.send(f"{ctx.author.mention} usuário não encontrado.", delete_after=5) await ctx.message.delete() elif isinstance(error, commands.CommandNotFound): return elif isinstance(error, commands.BotMissingPermissions): missing = ", ".join(map(lambda perm : "`perm`", error.missing_perms)) await ctx.reply(f"{ctx.author.mention} Eu não tenho a(s) permissão(ões) {missing}") elif isinstance(error, commands.MissingRequiredArgument): command = client.get_command("help") await ctx.invoke(command, cmd=ctx.command.name) elif isinstance(error, commands.DisabledCommand): await ctx.reply(f"Desculpe, mas o comando **{ctx.command.qualified_name}** está temporariamente desabilitado.") elif isinstance(error, commands.MissingPermissions): missing = ", ".join(error.missing_perms) await ctx.reply(f"Você não tem as seguintes permissões: `{missing}`") elif isinstance(error, UserBlacklisted): async with create_async_database("main.db") as connection: reason = await connection.get_item("blacklisteds", f"user_id = {ctx.author.id}", "reason") try: reason = reason[0] except (IndexError, TypeError): # não tem um motivo reason = "Nenhum..." await ctx.reply(f"Saia, você entrou pra lista negra. Motivo: **{reason}**") elif isinstance(error, commands.NotOwner): await ctx.reply("Este comando está reservado apenas para pessoas especiais. :3") else: traceback.print_exception(type(error), error, error.__traceback__, file=sys.stderr) descr = f"```{type(error).__name__}: {error}```" embed = discord.Embed(title="Houve um erro ao executar esse comando!", description=descr, color=discord.Color.dark_theme()) await ctx.send(ctx.author.mention, embed=embed)
async def blacklist(self, ctx, user: Union[discord.Member, discord.User], *, reason: str = None): """Deixa uma pessoa na lista negra. A lista negra é uma lista de usuários que impede elas de usarem os comandos do bot. **Veja também**: Comando `whitelist`.""" appinfo = await self.client.application_info() if user in appinfo.team.members: await ctx.reply("Você não pode dar blacklist em membros do time!" ) return fields = (Field(name="user_id", type="TEXT NOT NULL"), Field(name="reason", type="TEXT")) async with create_async_database("main.db") as wrap: await wrap.create_table_if_absent("blacklisteds", fields) write_blacklist(user, reason) await ctx.reply(f"O usuário {user} foi banido de usar o bot.")