Skip to content

Commit

Permalink
feat: 支持修改默认指令级别
Browse files Browse the repository at this point in the history
  • Loading branch information
rehiy committed Mar 20, 2024
1 parent 19fa111 commit 99a55f2
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 60 deletions.
3 changes: 3 additions & 0 deletions wclient/robot/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ func ResetHandlers() {
for _, v := range kws {
if hmap[v.Target] != nil {
hmap[v.Phrase+"@"+v.Roomid] = hmap[v.Target]
if v.Roomid == "*" {
hmap[v.Target].Level = v.Level
}
}
}
}
Expand Down
64 changes: 34 additions & 30 deletions webview/src/apps/keyword/create.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
</div>
</div>
<div class="col-12">
<label class="form-label">分组</label>
<select name="group" class="form-select" [(ngModel)]="formdata.group">
<label class="form-label">分组 *</label>
<select name="group" class="form-select" [(ngModel)]="formdata.group" required >
@for (item of keywordGroups | keyvalue; track item.key) {
<option [value]="item.key">{{item.value.name}}</option>
}
Expand All @@ -28,31 +28,6 @@
关键词分组,标记短语的作用
</div>
</div>
@if (formdata.group == 'badword') {
<div class="col-12">
<label class="form-label">级别</label>
<select name="level" class="form-select" [(ngModel)]="formdata.level">
@for (item of badwordLevels | keyvalue; track item.key) {
<option [value]="item.key">{{item.value.name}}</option>
}
</select>
<div class="form-text">
用于违规积分累计,当前计 {{formdata.level}} 分
</div>
</div>
} @else {
<div class="col-12">
<label class="form-label">级别</label>
<select name="level" class="form-select" [(ngModel)]="formdata.level">
@for (item of userLevels | keyvalue; track item.key) {
<option [value]="item.key">{{item.value.name}}</option>
}
</select>
<div class="form-text">
用于限制指令使用权限,对指令别名无效
</div>
</div>
}
<div class="col-12">
<label class="form-label">场景 *</label>
<select name="roomid" class="form-select" [(ngModel)]="formdata.roomid" required>
Expand All @@ -69,7 +44,7 @@
</div>
@if (formdata.group == 'command') {
<div class="col-12">
<label class="form-label">命令</label>
<label class="form-label">命令 *</label>
<textarea name="target" class="form-control" rows="3" [(ngModel)]="formdata.target" required></textarea>
<div class="form-text">
填写可执行程序的绝对路径及参数,如:<i>node.exe D:\wrest\app.js</i><br />
Expand All @@ -79,8 +54,8 @@
}
@if (formdata.group == 'handler') {
<div class="col-12">
<label class="form-label">指令</label>
<select name="target" class="form-select" [(ngModel)]="formdata.target">
<label class="form-label">指令 *</label>
<select name="target" class="form-select" [(ngModel)]="formdata.target" (change)="changeHandler()" required>
@for (item of robotHandler; track item.command) {
<option [value]="item.command">{{item.command}} {{item.describe}}</option>
}
Expand All @@ -90,6 +65,35 @@
</div>
</div>
}
@if (formdata.group == 'badword') {
<div class="col-12">
<label class="form-label">级别 *</label>
<select name="level" class="form-select" [(ngModel)]="formdata.level" required>
@for (item of badwordLevels | keyvalue; track item.key) {
<option [value]="item.key">{{item.value.name}}</option>
}
</select>
<div class="form-text">
用于违规积分累计,当前计 {{formdata.level}} 分
</div>
</div>
} @else {
<div class="col-12">
<label class="form-label">级别 *</label>
<select name="level" class="form-select" [(ngModel)]="formdata.level" required>
@for (item of userLevels | keyvalue; track item.key) {
<option [value]="item.key">{{item.value.name}}</option>
}
</select>
<div class="form-text">
@if (formdata.group == 'handler') {
全局别名级别设置将重写原指令级别,其他场景则忽略
} @else {
用于限制外部指令的使用权限
}
</div>
</div>
}
<div class="col-12">
<label class="form-label">备注</label>
<input type="text" name="remark" class="form-control" [(ngModel)]="formdata.remark" />
Expand Down
5 changes: 5 additions & 0 deletions webview/src/apps/keyword/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ export class KeywordCreateComponent {
});
}

public changeHandler() {
const h = this.robotHandler.find((h) => h.command === this.formdata.target);
this.formdata.level = h ? h.level : -1;
}

public getRobotHandlers() {
return SundryApi.handlerList({}).then((data) => {
this.robotHandler = data || [];
Expand Down
64 changes: 34 additions & 30 deletions webview/src/apps/keyword/update.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
</div>
</div>
<div class="col-12">
<label class="form-label">分组</label>
<select name="group" class="form-select" [(ngModel)]="formdata.group">
<label class="form-label">分组 *</label>
<select name="group" class="form-select" [(ngModel)]="formdata.group" required >
@for (item of keywordGroups | keyvalue; track item.key) {
<option [value]="item.key">{{item.value.name}}</option>
}
Expand All @@ -28,31 +28,6 @@
关键词分组,标记短语的作用
</div>
</div>
@if (formdata.group == 'badword') {
<div class="col-12">
<label class="form-label">级别</label>
<select name="level" class="form-select" [(ngModel)]="formdata.level">
@for (item of badwordLevels | keyvalue; track item.key) {
<option [value]="item.key">{{item.value.name}}</option>
}
</select>
<div class="form-text">
用于违规积分累计,当前计 {{formdata.level}} 分
</div>
</div>
} @else {
<div class="col-12">
<label class="form-label">级别</label>
<select name="level" class="form-select" [(ngModel)]="formdata.level">
@for (item of userLevels | keyvalue; track item.key) {
<option [value]="item.key">{{item.value.name}}</option>
}
</select>
<div class="form-text">
用于限制指令使用权限,对指令别名无效
</div>
</div>
}
<div class="col-12">
<label class="form-label">场景 *</label>
<select name="roomid" class="form-select" [(ngModel)]="formdata.roomid" required>
Expand All @@ -69,7 +44,7 @@
</div>
@if (formdata.group == 'command') {
<div class="col-12">
<label class="form-label">命令</label>
<label class="form-label">命令 *</label>
<textarea name="target" class="form-control" rows="3" [(ngModel)]="formdata.target" required></textarea>
<div class="form-text">
填写可执行程序的绝对路径及参数,如:<i>node.exe D:\wrest\app.js</i><br />
Expand All @@ -79,8 +54,8 @@
}
@if (formdata.group == 'handler') {
<div class="col-12">
<label class="form-label">指令</label>
<select name="target" class="form-select" [(ngModel)]="formdata.target">
<label class="form-label">指令 *</label>
<select name="target" class="form-select" [(ngModel)]="formdata.target" (change)="changeHandler()" required>
@for (item of robotHandler; track item.command) {
<option [value]="item.command">{{item.command}} {{item.describe}}</option>
}
Expand All @@ -90,6 +65,35 @@
</div>
</div>
}
@if (formdata.group == 'badword') {
<div class="col-12">
<label class="form-label">级别 *</label>
<select name="level" class="form-select" [(ngModel)]="formdata.level" required>
@for (item of badwordLevels | keyvalue; track item.key) {
<option [value]="item.key">{{item.value.name}}</option>
}
</select>
<div class="form-text">
用于违规积分累计,当前计 {{formdata.level}} 分
</div>
</div>
} @else {
<div class="col-12">
<label class="form-label">级别 *</label>
<select name="level" class="form-select" [(ngModel)]="formdata.level" required>
@for (item of userLevels | keyvalue; track item.key) {
<option [value]="item.key">{{item.value.name}}</option>
}
</select>
<div class="form-text">
@if (formdata.group == 'handler') {
全局别名级别设置将重写原指令级别,其他场景则忽略
} @else {
用于限制外部指令的使用权限
}
</div>
</div>
}
<div class="col-12">
<label class="form-label">备注</label>
<input type="text" name="remark" class="form-control" [(ngModel)]="formdata.remark" />
Expand Down
5 changes: 5 additions & 0 deletions webview/src/apps/keyword/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ export class KeywordUpdateComponent implements OnInit {
});
}

public changeHandler() {
const h = this.robotHandler.find((h) => h.command === this.formdata.target);
this.formdata.level = h ? h.level : -1;
}

public getRobotHandlers() {
return SundryApi.handlerList({}).then((data) => {
this.robotHandler = data || [];
Expand Down

0 comments on commit 99a55f2

Please sign in to comment.