Created
September 21, 2020 19:46
-
-
Save xtrm-en/a554d2717e47f5f3ff68e3a9606799b6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
""" | |
Permission Parser v1.0.1 | |
Contains various utilities to parse Discord's permissions. | |
""" | |
# Default Discord permissions values | |
# From https://github.com/discord/discord-api-docs/blob/master/docs/topics/Permissions.md | |
default_permissions = { | |
"CREATE_INSTANT_INVITE": 0x1, | |
"KICK_MEMBERS": 0x2, | |
"BAN_MEMBERS ": 0x4, | |
"ADMINISTRATOR ": 0x8, | |
"MANAGE_CHANNELS ": 0x10, | |
"MANAGE_GUILD ": 0x20, | |
"ADD_REACTIONS": 0x40, | |
"VIEW_AUDIT_LOG": 0x80, | |
"PRIORITY_SPEAKER": 0x100, | |
"STREAM": 0x200, | |
"VIEW_CHANNEL": 0x400, | |
"SEND_MESSAGES": 0x800, | |
"SEND_TTS_MESSAGES": 0x1000, | |
"MANAGE_MESSAGES ": 0x2000, | |
"EMBED_LINKS": 0x4000, | |
"ATTACH_FILES": 0x8000, | |
"READ_MESSAGE_HISTORY": 0x10000, | |
"MENTION_EVERYONE": 0x20000, | |
"USE_EXTERNAL_EMOJIS": 0x40000, | |
"VIEW_GUILD_INSIGHTS": 0x80000, | |
"CONNECT": 0x100000, | |
"SPEAK": 0x200000, | |
"MUTE_MEMBERS": 0x400000, | |
"DEAFEN_MEMBERS": 0x800000, | |
"MOVE_MEMBERS": 0x1000000, | |
"USE_VAD": 0x2000000, | |
"CHANGE_NICKNAME": 0x4000000, | |
"MANAGE_NICKNAMES": 0x8000000, | |
"MANAGE_ROLES ": 0x10000000, | |
"MANAGE_WEBHOOKS ": 0x20000000, | |
"MANAGE_EMOJIS ": 0x40000000, | |
} | |
class PermissiveObject: | |
""" | |
A class used to represent an Object with an int permission value. | |
""" | |
def __init__(self, permission_value: int = 0): | |
self.permission_value = permission_value | |
def has_permission(self, permission_key: str): | |
""" | |
Returns wheather or not this object possesses this permission. | |
- Note this doesn't take into account, in the instance of a guild and | |
if this object is a member, if this member is the guild's owner. | |
""" | |
# null check | |
if str is None: | |
return False | |
# administrator check | |
if self.permission_value & 0x8 == 0x8: | |
return True | |
return self.permission_value & default_permissions.get(permission_key) == default_permissions.get(permission_key) | |
__author__ = "xTrM_" | |
__version__ = "1.0.1" | |
__status__ = "Production" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
O gode tanks yoo xtramway aïe love zis