Skip to content

Commit 95bbdbd

Browse files
committed
fix(tasks): parse malformed quest titles
imagine if these were consistent 😠
1 parent a403e20 commit 95bbdbd

File tree

4 files changed

+22
-21
lines changed

4 files changed

+22
-21
lines changed

src/views/Tasks/hooks/useParser/getTask.ts

+3-11
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
WorshipTask,
99
} from "../../store"
1010
import { getType } from "./getType"
11+
import { getCardText } from "./utils"
1112

1213
const complexTaskToParserMap: Record<ComplexTaskType, (el: HTMLElement) => Task> = {
1314
[TaskType.WORSHIP]: getWorshipTask,
@@ -53,15 +54,6 @@ function getText(el: HTMLElement): string {
5354
return el.querySelector<HTMLSpanElement>("span.truncate")?.innerText ?? ""
5455
}
5556

56-
function getCardText(el: HTMLElement): string {
57-
const onclickData = el.getAttribute("onclick")
58-
if (!onclickData) return "No meta found"
59-
60-
const meta = onclickData.slice(onclickData.indexOf("('")).replace(/[)(]/g, "")
61-
const parsedMeta = JSON.parse(`[${meta.replace(/"/g, '\\"').replace(/'/g, '"')}]`)
62-
return parsedMeta[1]
63-
}
64-
6557
function getKillSomeTask(el: HTMLElement): KillSomeTask {
6658
const [progress, requirement] = getProgress(el)
6759
const [title, icon] = getMeta(el)
@@ -91,8 +83,8 @@ function getQuestSomeTask(el: HTMLElement): QuestSomeTask {
9183
const [progress, requirement] = getProgress(el)
9284
const [title, icon] = getMeta(el)
9385

94-
const text = getText(el)
95-
const target = text.match(/(?<=Complete the quest )(.*)(?= [0-9])/g)?.[0] ?? "UNKNOWN TARGET"
86+
const cardText = getCardText(el)
87+
const target = cardText.match(/(?<=Complete the quest )(.*)(?= [0-9])/g)?.[0]?.replace(/"/g, "") ?? "UNKNOWN TARGET"
9688

9789
return {
9890
type: TaskType.QUEST_SOME,

src/views/Tasks/hooks/useParser/getType.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { TaskType } from "../../store"
2+
import { getCardText } from "@/views/Tasks/hooks/useParser/utils"
23

34
const regexpToTypeMap: Array<[RegExp, TaskType]> = [
45
[/kill.*times/gi, TaskType.KILL_SOME],
@@ -12,7 +13,7 @@ const regexpToTypeMap: Array<[RegExp, TaskType]> = [
1213
]
1314

1415
export function getType(el: HTMLElement): TaskType {
15-
const text = el.querySelector<HTMLSpanElement>("span.truncate")?.innerText || ""
16+
const text = getCardText(el)
1617
const [_, type] = regexpToTypeMap.find(([regexp]) => text.match(regexp)) ?? []
1718
return type ?? TaskType.UNKNOWN
1819
}
+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export function getCardText(el: HTMLElement): string {
2+
const onclickData = el.getAttribute("onclick")
3+
if (!onclickData) return "No meta found"
4+
5+
const meta = onclickData.slice(onclickData.indexOf("('")).replace(/[)(]/g, "")
6+
const parsedMeta = JSON.parse(`[${meta.replace(/"/g, '\\"').replace(/'/g, '"')}]`)
7+
return parsedMeta[1]
8+
}

src/views/Tasks/store.ts

+9-9
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,15 @@ export const useTasksStore = defineStore(
6262
)
6363

6464
export enum TaskType {
65-
QUEST_SOME,
66-
QUEST_ANY,
67-
KILL_SOME,
68-
KILL_ANY,
69-
STEP,
70-
WORSHIP,
71-
VOTE,
72-
BUY,
73-
UNKNOWN,
65+
QUEST_SOME = "QUEST_SOME",
66+
QUEST_ANY = "QUEST_ANY",
67+
KILL_SOME = "KILL_SOME",
68+
KILL_ANY = "KILL_ANY",
69+
STEP = "STEP",
70+
WORSHIP = "WORSHIP",
71+
VOTE = "VOTE",
72+
BUY = "BUY",
73+
UNKNOWN = "UNKNOWN",
7474
}
7575

7676
export type ComplexTaskType = Extract<TaskType, TaskType.WORSHIP | TaskType.QUEST_SOME | TaskType.KILL_SOME>

0 commit comments

Comments
 (0)