-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathevent_demo.py
46 lines (34 loc) · 1.53 KB
/
event_demo.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
from nonebot import logger
from nonebot_plugin_access_control_api.service import Service
from nonebot_plugin_access_control_api.models.permission import Permission
from nonebot_plugin_access_control_api.models.rate_limit import RateLimitRule
from .plugin_service import plugin_service
from .matcher_demo import a_service, b_service, c_service
@plugin_service.on_set_permission
async def _(service: Service, permission: Permission):
logger.debug(
f"on set permission: {service} {permission.subject}, "
f"now allow={permission.allow}"
)
@plugin_service.on_remove_permission
async def _(service: Service, subject: str):
allow = await service.get_permission_by_subject(subject)
logger.debug(f"on remove permission: {service} {subject}, " f"now allow={allow}")
@a_service.on_change_permission
@b_service.on_change_permission
@c_service.on_change_permission
async def _(service: Service, permission: Permission):
logger.debug(
f"on change permission: {service} {permission.subject}, "
f"now allow={permission.allow}"
)
@a_service.on_add_rate_limit_rule
@b_service.on_add_rate_limit_rule
@c_service.on_add_rate_limit_rule
async def _(service: Service, rule: RateLimitRule):
logger.debug(f"on add rate limit rule: #{rule.id} {service} {rule.subject}")
@a_service.on_remove_rate_limit_rule
@b_service.on_remove_rate_limit_rule
@c_service.on_remove_rate_limit_rule
async def _(service: Service, rule: RateLimitRule):
logger.debug(f"on remove rate limit rule: #{rule.id} {service} {rule.subject}")