.
This commit is contained in:
1 parent
90a7cf6a7e
commit
905bbcc6dd
9 files changed
+122
-67
No files matched your search
@@ -3,7 +3,7 @@ import mongoose from 'mongoose';
|
||||
import { NatsService } from '../global/nats/nats.service';
|
||||
import { SecretService } from '../global/secret/secret.service';
|
||||
import { CommandParseError, parseCommand } from './parsers/command.parser';
|
||||
import { DakaoInboundEvent, DakaoSegment } from './dakao.types';
|
||||
import { DakaoInboundEvent, DakaoLong, DakaoSegment } from './dakao.types';
|
||||
import { DakaoPublisher } from './dakao.publisher';
|
||||
import { DakaoUserError, DakaoUserService } from './dakao-user.service';
|
||||
import { IdempotencyCache } from './idempotency.cache';
|
||||
@@ -81,16 +81,17 @@ export class DakaoSubscriber implements OnModuleInit {
|
||||
}
|
||||
|
||||
let segments: DakaoSegment[];
|
||||
const senderNickname = this.resolveSenderNickname(event);
|
||||
const correlationId = this.serializeDakaoLong(event.origin.chatLog.logId);
|
||||
try {
|
||||
const command = parseCommand(event.origin.chatLog.message);
|
||||
const correlationId = String(event.origin.chatLog.logId ?? '');
|
||||
|
||||
switch (command.kind) {
|
||||
case 'match-list':
|
||||
segments = await this.matchListHandler.handle({
|
||||
communityId,
|
||||
senderUserId: event.userId,
|
||||
senderNickname: event.nickname,
|
||||
senderNickname,
|
||||
});
|
||||
break;
|
||||
case 'match-join':
|
||||
@@ -98,7 +99,7 @@ export class DakaoSubscriber implements OnModuleInit {
|
||||
communityId,
|
||||
matchId: command.matchId,
|
||||
senderUserId: event.userId,
|
||||
senderNickname: event.nickname,
|
||||
senderNickname,
|
||||
gameName: command.gameName,
|
||||
tagLine: command.tagLine,
|
||||
positions: command.positions.positions,
|
||||
@@ -117,8 +118,8 @@ export class DakaoSubscriber implements OnModuleInit {
|
||||
if (err.code === 'not_a_command') return;
|
||||
await this.publisher.sendMessage({
|
||||
chatroomId: event.chatroomId,
|
||||
segments: this.parseErrorReply(event, err),
|
||||
correlationId: String(event.origin.chatLog.logId ?? ''),
|
||||
segments: this.parseErrorReply(event, senderNickname, err),
|
||||
correlationId,
|
||||
});
|
||||
return;
|
||||
}
|
||||
@@ -145,24 +146,38 @@ export class DakaoSubscriber implements OnModuleInit {
|
||||
}
|
||||
|
||||
private deriveLogIdKey(event: DakaoInboundEvent): string | null {
|
||||
const logId = event.origin.chatLog.logId;
|
||||
if (typeof logId === 'string') return `${event.projectId}:${logId}`;
|
||||
if (logId && typeof logId === 'object') {
|
||||
const { high, low, unsigned } = logId;
|
||||
return `${event.projectId}:${high ?? ''}|${low ?? ''}|${unsigned ?? ''}`;
|
||||
}
|
||||
return null;
|
||||
const serialized = this.serializeDakaoLong(event.origin.chatLog.logId);
|
||||
return serialized ? `${event.projectId}:${serialized}` : null;
|
||||
}
|
||||
|
||||
private serializeDakaoLong(value: DakaoLong | string | undefined): string {
|
||||
if (typeof value === 'string') return value;
|
||||
if (!value || typeof value !== 'object') return '';
|
||||
const high = BigInt(value.high ?? 0);
|
||||
const low = BigInt.asUintN(32, BigInt(value.low ?? 0));
|
||||
const combined = (high << 32n) | low;
|
||||
return value.unsigned
|
||||
? BigInt.asUintN(64, combined).toString()
|
||||
: BigInt.asIntN(64, combined).toString();
|
||||
}
|
||||
|
||||
private resolveSenderNickname(event: DakaoInboundEvent): string {
|
||||
const primary = event.nickname?.trim();
|
||||
if (primary) return primary;
|
||||
const fallback = event.origin.authorNickname?.trim();
|
||||
return fallback ?? '';
|
||||
}
|
||||
|
||||
private parseErrorReply(
|
||||
event: DakaoInboundEvent,
|
||||
senderNickname: string,
|
||||
err: CommandParseError,
|
||||
): DakaoSegment[] {
|
||||
const head: DakaoSegment[] = [
|
||||
{
|
||||
kind: 'mention',
|
||||
userId: event.userId,
|
||||
displayText: event.nickname,
|
||||
displayText: senderNickname,
|
||||
},
|
||||
];
|
||||
const text = ((): string => {
|
||||
|
||||
@@ -43,7 +43,7 @@ describe('MatchJoinHandler', () => {
|
||||
expect.objectContaining({ kind: 'mention', userId: 'kakao-user-1' }),
|
||||
expect.objectContaining({
|
||||
kind: 'text',
|
||||
text: expect.stringContaining('유효하지 않은 매치 ID'),
|
||||
text: expect.stringContaining('유효하지 않은 내전 ID'),
|
||||
}),
|
||||
]);
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user