def blacklist(self, ctx, server_or_user: _GuildOrUser, *, reason=''):
"""Blacklists either a server or a user, from using the bot."""
if await ctx.bot.is_owner(server_or_user):
return await ctx.send("You can't blacklist my sensei you baka...")
time = datetime.datetime.utcnow()
row = Blacklist(
snowflake=server_or_user.id,
blacklisted_at=time,
reason=reason
)
try:
async with ctx.db.get_session() as session:
await session.add(row)
except asyncpg.UniqueViolationError:
return await ctx.send(f'{server_or_user} has already been blacklisted.')
else:
await self._show_blacklist_embed(ctx, 0xd50000, 'blacklisted', _blocked_icon,
server_or_user, reason, time)
python类is_owner()的实例源码
def __local_check(self, ctx):
return await ctx.bot.is_owner(ctx.author)
def unblacklist(self, ctx, server_or_user: _GuildOrUser, *, reason=''):
"""Removes either a server or a user from the blacklist."""
if await ctx.bot.is_owner(server_or_user):
return await ctx.send("You can't blacklist my sensei you baka...")
async with ctx.db.get_session() as session:
query = session.select.from_(Blacklist).where(Blacklist.snowflake == server_or_user.id)
row = await query.first()
if not row:
return await ctx.send(f"{server_or_user} isn't blacklisted.")
await session.remove(row)
await self._show_blacklist_embed(ctx, 0x4CAF50, 'unblacklisted', _unblocked_icon,
server_or_user, reason, datetime.datetime.utcnow())
def check_privilege(self, ctx):
"""Displays your privilege rank."""
if await self.nyx.is_owner(ctx.message.author):
privilege = "Owner"
else:
privilege = str(
self.nyx.get_user_data(ctx.message.author).get_privilege())
if ctx.message.guild is None:
await ctx.send("Privilege: " + privilege)
else:
await ctx.send("".join(
[ctx.message.author.mention, ", your privilege level is ",
privilege, "."]))