Compare commits
No commits in common. "ff6c1627b0f230721ab19a8561533ded870421ec" and "5a331e773d88fd79cdd7048288a139deb0c9b64a" have entirely different histories.
ff6c1627b0
...
5a331e773d
10
cmds.py
10
cmds.py
@ -64,8 +64,9 @@ def cmds(app, data):
|
|||||||
action="store_true")
|
action="store_true")
|
||||||
parser.add_argument('-g', '--group', help='组名')
|
parser.add_argument('-g', '--group', help='组名')
|
||||||
parser.add_argument('-m', '--command', help='命令名')
|
parser.add_argument('-m', '--command', help='命令名')
|
||||||
parser.add_argument('-au', '--adduser', help='添加用户/群到组',
|
parser.add_argument('-au', '--adduser', help='添加用户到组',
|
||||||
action="store_true")
|
action="store_true")
|
||||||
|
parser.add_argument('-u', '--user', help='用户QQ号')
|
||||||
|
|
||||||
args = parser.parse_args(sqt.args)
|
args = parser.parse_args(sqt.args)
|
||||||
e: AsyncEnforcer = sqt.app.ctx.e
|
e: AsyncEnforcer = sqt.app.ctx.e
|
||||||
@ -79,9 +80,9 @@ def cmds(app, data):
|
|||||||
else:
|
else:
|
||||||
msg = Message(content='缺失参数,请使用-h查看帮助', room_id=sqt.room_id)
|
msg = Message(content='缺失参数,请使用-h查看帮助', room_id=sqt.room_id)
|
||||||
if args.adduser:
|
if args.adduser:
|
||||||
if args.group:
|
if args.user and args.group:
|
||||||
if await e.add_role_for_user(str(sqt.room_id), args.group):
|
if await e.add_role_for_user(args.user, args.group):
|
||||||
msg = Message(content=f'添加成功:g, {sqt.room_id}, {args.group}', room_id=sqt.room_id)
|
msg = Message(content=f'添加成功:g, {args.user}, {args.group}', room_id=sqt.room_id)
|
||||||
else:
|
else:
|
||||||
msg = Message(content='添加失败,用户已在组内或其它错误', room_id=sqt.room_id)
|
msg = Message(content='添加失败,用户已在组内或其它错误', room_id=sqt.room_id)
|
||||||
else:
|
else:
|
||||||
@ -93,6 +94,5 @@ def cmds(app, data):
|
|||||||
if msg == '':
|
if msg == '':
|
||||||
msg = Message(content='参数错误,请使用-h查看帮助', room_id=sqt.room_id)
|
msg = Message(content='参数错误,请使用-h查看帮助', room_id=sqt.room_id)
|
||||||
await sqt.app.ctx.sio.emit('sendMessage', msg.to_json())
|
await sqt.app.ctx.sio.emit('sendMessage', msg.to_json())
|
||||||
await e.save_policy()
|
|
||||||
|
|
||||||
return sio_decorator
|
return sio_decorator
|
||||||
|
35
sio_model.py
35
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, AsyncEnforcer
|
from casbin import Enforcer
|
||||||
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,25 +117,22 @@ 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:
|
||||||
e: AsyncEnforcer = self.app.ctx.e
|
parser = ArgumentParser(self._cmd[0])
|
||||||
if (e.enforce(str(room_id), self._cmd[0][1:]) or
|
|
||||||
(await e.has_role_for_user(str(sender_id), 'admin'))):
|
|
||||||
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