本文整理汇总了Python中permissions.Permissions.check_permission方法的典型用法代码示例。如果您正苦于以下问题:Python Permissions.check_permission方法的具体用法?Python Permissions.check_permission怎么用?Python Permissions.check_permission使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类permissions.Permissions
的用法示例。
在下文中一共展示了Permissions.check_permission方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from permissions import Permissions [as 别名]
# 或者: from permissions.Permissions import check_permission [as 别名]
#.........这里部分代码省略.........
def hook_numeric(self, numeric, callback):
"""
Register a raw numeric hook to the bot.
@param numeric: The raw IRC numeric (or command, such as PRIVMSG) to hook.
@param callback: Event callback function to call when this numeric/command is received from the server.
@return: ID of the new hook. (Used for removal later)
"""
return self.hook_manager.add_hook(Hook("irc_raw_%s" % numeric, callback))
def list_commands(self):
"""
Get a list of all commands the bot knows about.
@return: list of command names
"""
return [hook[8:] for hook in self.hook_manager.hooks.keys() if hook.startswith("command_")] # len("command_") == 8
def unhook_something(self, the_id):
"""
Unhook any sort of hook. (Command, numeric, or event.)
@param the_id: The ID of the hook to remove, returned by a hook adding function.
"""
self.hook_manager.remove_hook(the_id)
def is_admin(self, hostmask=None):
"""
Check if a hostmask is a bot admin.
@param hostmask: The hostmask to check.
@return: True if admin, False if not.
"""
if hostmask is None:
hostmask = self.state["last_line"].hostmask
return self.perms.check_permission(hostmask, "admin")
def check_condition(self, condition, false_message="Sorry, you may not do that.", reply_func=None):
"""
Check a condition and return it, calling reply_func with false_message if the condition is False.
@param condition: The condition to check.
@param false_message: The message to be passed to reply_func
@param reply_func: The function to call with false_message as argument if condition is False.
@return:
"""
if reply_func is None:
reply_func = self.reply
if condition:
return True
reply_func(false_message)
return False
def check_permission(self, permission="admin", error_reply="Sorry, you do not have permission to do that!",
reply_func=None):
"""
Check a bot permission against the hostmask of the last line received, and return whether it matches.
Calls reply_func with error_reply as argument if condition is False
@param permission: The permission to check.
@param error_reply: The message to be passed to reply_func
@param reply_func: The function to call with error_reply as argument if condition is False.
@return:
"""
if reply_func is None:
reply_func = self.reply_notice
return self.check_condition(self.perms.check_permission(self.state["last_line"].hostmask, permission),