Skip to content

Commit 5265f93

Browse files
committed
feat: 新增自动角色判断,导入后自动过滤空消息
1 parent a69a35d commit 5265f93

2 files changed

Lines changed: 32 additions & 14 deletions

File tree

src/components/panels/IdentityPanel.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
<option value="gm">主持人</option>
7474
<option value="bot">骰子</option>
7575
<option value="ob">观众</option>
76-
<option value="unknown">未知</option>
76+
<option value="unknown">其他</option>
7777
</select>
7878
</div>
7979
<div class="col-divider"></div>

src/io/import/parser.ts

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,14 @@ export function transformRowToMessage(
1414
row: ImportRow,
1515
index: number,
1616
importTime: Date,
17-
): Message {
17+
roleConfig: RoleKeywordConfig = defaultRoleConfig,
18+
): Message | null {
19+
// 删掉清洗之后剩下的空消息
20+
const content = row.content || '';
21+
if (content.trim().length === 0) {
22+
return null;
23+
}
24+
1825
let name = row.playerName?.trim() || '';
1926
let account = row.account?.trim() || '';
2027
let note = row.note?.trim() || '';
@@ -29,7 +36,6 @@ export function transformRowToMessage(
2936
account = `${name}_ID`;
3037
}
3138

32-
const content = row.content;
3339
const firstLine = content.split('\n')[0] || '';
3440

3541
// OOC 与 指令判定
@@ -47,7 +53,7 @@ export function transformRowToMessage(
4753
content,
4854
isOoc,
4955
isCommand,
50-
role: inferRole(name),
56+
role: inferRole(name, roleConfig),
5157
note,
5258
};
5359
}
@@ -129,9 +135,10 @@ export function buildLogDocument(
129135
): LogDocument {
130136
const docId = generateId();
131137
const importTime = new Date();
132-
const messages = rows.map((r, i) =>
133-
transformRowToMessage(r, i, importTime),
134-
);
138+
const messages = rows
139+
.map((r, i) => transformRowToMessage(r, i, importTime))
140+
.filter((m): m is Message => m !== null);
141+
135142
const chunks = chunkMessages(messages, docId, splitKeyword);
136143

137144
return {
@@ -144,14 +151,25 @@ export function buildLogDocument(
144151
}
145152

146153
//----辅助函数----
147-
148-
//TODO: 占位,自动角色判断规则后面再补
149-
function inferRole(name: string): RoleType {
154+
interface RoleKeywordConfig {
155+
gm: string[];
156+
bot: string[];
157+
ob: string[];
158+
npc: string[];
159+
}
160+
const defaultRoleConfig: RoleKeywordConfig = {
161+
gm: ['gm', 'kp', 'dm', 'st', 'dh', '主持人', '守密人'],
162+
bot: ['bot', '骰娘', '骰子'],
163+
ob: ['ob', '观众'],
164+
npc: ['npc'],
165+
};
166+
167+
function inferRole(name: string, config: RoleKeywordConfig): RoleType {
150168
const lower = name.toLowerCase();
151-
if (lower.includes('gm')) return 'gm';
152-
if (lower.includes('bot')) return 'bot';
153-
if (lower.includes('ob')) return 'ob';
154-
if (lower.includes('npc')) return 'npc';
169+
if (config.gm.some((k) => lower.includes(k.toLowerCase()))) return 'gm';
170+
if (config.bot.some((k) => lower.includes(k.toLowerCase()))) return 'bot';
171+
if (config.ob.some((k) => lower.includes(k.toLowerCase()))) return 'ob';
172+
if (config.npc.some((k) => lower.includes(k.toLowerCase()))) return 'npc';
155173
return 'pl';
156174
}
157175

0 commit comments

Comments
 (0)