-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpermissions.py
61 lines (46 loc) · 2.21 KB
/
permissions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import discord
from utils import default
from discord.ext import commands
owners = default.config()["owners"]
def is_owner(ctx):
""" Checks if the author is one of the owners """
return ctx.author.id in owners
async def check_permissions(ctx, perms, *, check=all):
""" Checks if author has permissions to a permission """
if ctx.author.id in owners:
return True
resolved = ctx.channel.permissions_for(ctx.author)
return check(getattr(resolved, name, None) == value for name, value in perms.items())
def has_permissions(*, check=all, **perms):
""" discord.Commands method to check if author has permissions """
async def pred(ctx):
return await check_permissions(ctx, perms, check=check)
return commands.check(pred)
async def check_priv(ctx, member):
""" Custom (weird) way to check permissions when handling moderation commands """
try:
# Self checks
if member == ctx.author:
return await ctx.send(f"You can't {ctx.command.name} yourself")
if member.id == ctx.bot.user.id:
return await ctx.send("So that's what you think of me huh..? sad ;-;")
# Check if user bypasses
if ctx.author.id == ctx.guild.owner.id:
return False
# Now permission check
if member.id in owners:
if ctx.author.id not in owners:
return await ctx.send(f"I can't {ctx.command.name} my creator ;-;")
else:
pass
if member.id == ctx.guild.owner.id:
return await ctx.send(f"You can't {ctx.command.name} the owner, lol")
if ctx.author.top_role == member.top_role:
return await ctx.send(f"You can't {ctx.command.name} someone who has the same permissions as you...")
if ctx.author.top_role < member.top_role:
return await ctx.send(f"Nope, you can't {ctx.command.name} someone higher than yourself.")
except Exception:
pass
def can_handle(ctx, permission: str):
""" Checks if bot has permissions or is in DMs right now """
return isinstance(ctx.channel, discord.DMChannel) or getattr(ctx.channel.permissions_for(ctx.guild.me), permission)