Last active
June 14, 2020 06:52
-
-
Save nkpro2000sr/641b566a58fc60cc4b7559a045bc8ef3 to your computer and use it in GitHub Desktop.
To check Roles and Permissions from anywhere. https://github.com/nkpro2000sr/discord-rebot
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
""" | |
To make non strict mode Roles and Permissions checks for discord-rebot | |
Example:: | |
Fn.auth = Roles['Admin'] # this will not allow DM or from other guild | |
Fn.auth = Anywhere(Roles['Admin']) # will allow | |
""" | |
import asyncio | |
import discord | |
from discordRebot import Converter, Authorize | |
class Anywhere: | |
""" | |
To allow message from anywhere, for authorizing Roles or Permissions | |
""" | |
bot = NotImplemented | |
def __init__(self, auths, bot=None): | |
""" | |
Args: | |
auth (Roles, Permissions, Set(Union[Roles, Permissions])): authorized | |
""" | |
self.auths = auths | |
if bot is not None: | |
self.bot = bot | |
def __call__(self, message): | |
"""An auth (since self is Callable[[Message], bool] in discordRebot.manager.Auth) | |
Args: | |
message (Message): message passed to callback | |
Returns: | |
(bool): True if authorized else False | |
""" | |
if self.bot is NotImplemented: | |
raise NotImplementedError("set Anywhere.bot or pass bot") | |
Convert = Converter(self.bot) | |
member = asyncio.run(Convert(message, str(message.author.id), discord.Member)) | |
message = type("dummy message", (), {}) | |
message.author = member | |
return bool(Authorize(self.auths, message)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment