正式给指令添加权限限制
This commit is contained in:
parent
5a331e773d
commit
31098af84b
34
sio_model.py
34
sio_model.py
@ -3,7 +3,7 @@ from dataclasses import dataclass
|
|||||||
from functools import wraps
|
from functools import wraps
|
||||||
from typing import Optional, List, Union, Literal, Dict, Any
|
from typing import Optional, List, Union, Literal, Dict, Any
|
||||||
|
|
||||||
from casbin import Enforcer
|
from casbin import Enforcer, AsyncEnforcer
|
||||||
from pydantic import BaseModel, Field, model_validator
|
from pydantic import BaseModel, Field, model_validator
|
||||||
from sanic import Sanic
|
from sanic import Sanic
|
||||||
from sanic.log import logger
|
from sanic.log import logger
|
||||||
@ -117,22 +117,24 @@ class SioDecorator:
|
|||||||
room_id = self.data['roomId']
|
room_id = self.data['roomId']
|
||||||
|
|
||||||
if sender_id != self.app.ctx.sio_config.self_id:
|
if sender_id != self.app.ctx.sio_config.self_id:
|
||||||
parser = ArgumentParser(self._cmd[0])
|
e: AsyncEnforcer = self.app.ctx.e
|
||||||
|
if e.enforce(str(sender_id), self._cmd[0][1:]):
|
||||||
|
parser = ArgumentParser(self._cmd[0])
|
||||||
|
|
||||||
sqt = SioRequest(app=self.app,
|
sqt = SioRequest(app=self.app,
|
||||||
parser=parser,
|
parser=parser,
|
||||||
args=self._cmd[1:],
|
args=self._cmd[1:],
|
||||||
key=self._cmd[0],
|
key=self._cmd[0],
|
||||||
sender_id=sender_id,
|
sender_id=sender_id,
|
||||||
sender_name=sender_name,
|
sender_name=sender_name,
|
||||||
content=self._content,
|
content=self._content,
|
||||||
room_id=room_id,
|
room_id=room_id,
|
||||||
data=self.data)
|
data=self.data)
|
||||||
try:
|
try:
|
||||||
await func(sqt)
|
await func(sqt)
|
||||||
except PrintMessage as e:
|
except PrintMessage as e:
|
||||||
msg = Message(content=str(e), room_id=room_id)
|
msg = Message(content=str(e), room_id=room_id)
|
||||||
await self.app.ctx.sio.emit('sendMessage', msg.to_json())
|
await self.app.ctx.sio.emit('sendMessage', msg.to_json())
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
|
Loading…
Reference in New Issue
Block a user