Commit 8cfffff2 authored by nanahira's avatar nanahira

support -t at

parent c73b09e9
Pipeline #16628 passed with stages
in 3 minutes and 28 seconds
This diff is collapsed.
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
"test:e2e": "jest --config ./test/jest-e2e.json" "test:e2e": "jest --config ./test/jest-e2e.json"
}, },
"dependencies": { "dependencies": {
"@koishijs/plugin-adapter-onebot": "^5.0.7", "@koishijs/plugin-adapter-onebot": "^5.1.3",
"@nestjs/common": "^8.0.0", "@nestjs/common": "^8.0.0",
"@nestjs/config": "^2.0.0", "@nestjs/config": "^2.0.0",
"@nestjs/core": "^8.0.0", "@nestjs/core": "^8.0.0",
...@@ -30,8 +30,8 @@ ...@@ -30,8 +30,8 @@
"@nestjs/typeorm": "^8.0.3", "@nestjs/typeorm": "^8.0.3",
"class-transformer": "^0.5.1", "class-transformer": "^0.5.1",
"class-validator": "^0.13.2", "class-validator": "^0.13.2",
"koishi": "^4.8.5", "koishi": "^4.9.1",
"koishi-nestjs": "^6.0.3", "koishi-nestjs": "^6.0.5",
"moment": "^2.29.2", "moment": "^2.29.2",
"pg": "^8.7.3", "pg": "^8.7.3",
"pg-native": "^3.0.0", "pg-native": "^3.0.0",
......
...@@ -6,7 +6,7 @@ import { ...@@ -6,7 +6,7 @@ import {
PutSession, PutSession,
UseCommand, UseCommand,
} from 'koishi-nestjs'; } from 'koishi-nestjs';
import { Bot, Session } from 'koishi'; import { Bot, segment, Session } from 'koishi';
import { RecordService } from '../record/record.service'; import { RecordService } from '../record/record.service';
import { OneBotBot } from '@koishijs/plugin-adapter-onebot'; import { OneBotBot } from '@koishijs/plugin-adapter-onebot';
...@@ -26,13 +26,24 @@ export class CommandService extends ConsoleLogger { ...@@ -26,13 +26,24 @@ export class CommandService extends ConsoleLogger {
return; return;
} }
private parseTarget(id: string) {
if (!id) return;
if (id.match(/^\d+$/)) return id;
const seg = segment.parse(id);
const target = seg.find((s) => s.type === 'at');
if (!target) return;
const { attrs } = target;
return attrs.id;
}
@OnChannel(...(process.env.TARGET_GUILDS?.split(',') || [])) @OnChannel(...(process.env.TARGET_GUILDS?.split(',') || []))
@UseCommand('rank [rank:string]', 'Ask for a rank') @UseCommand('rank [rank:string]', 'Ask for a rank')
async rankCommand( async rankCommand(
@PutSession() session: Session, @PutSession() session: Session,
@PutArg(0) rank: string, @PutArg(0) rank: string,
@PutOption('targetId', '-t <targetId>') targetId: string, @PutOption('targetId', '-t <targetId>') rawTargetId: string,
) { ) {
const targetId = this.parseTarget(rawTargetId);
const rankUserId = targetId || session.userId; const rankUserId = targetId || session.userId;
const actionDescription = `rank ${rank} to ${rankUserId} by ${session.userId}`; const actionDescription = `rank ${rank} to ${rankUserId} by ${session.userId}`;
if (targetId) { if (targetId) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment