-
-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathindex.ts
77 lines (63 loc) · 2.88 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import { Action, UnknownAction } from "../interfaces/actions";
import { YTAction } from "../interfaces/yt/chat";
import { debugLog, omitTrackingParams } from "../utils";
import { parseAddBannerToLiveChatCommand } from "./actions/addBannerToLiveChatCommand";
import { parseAddChatItemAction } from "./actions/addChatItemAction";
import { parseAddLiveChatTickerItemAction } from "./actions/addLiveChatTickerItemAction";
import { parseCloseLiveChatActionPanelAction } from "./actions/closeLiveChatActionPanelAction";
import { parseMarkChatItemAsDeletedAction } from "./actions/markChatItemAsDeletedAction";
import { parseMarkChatItemsByAuthorAsDeletedAction } from "./actions/markChatItemsByAuthorAsDeletedAction";
import { parseRemoveBannerForLiveChatCommand } from "./actions/removeBannerForLiveChatCommand";
import { parseReplaceChatItemAction } from "./actions/replaceChatItemAction";
import { parseShowLiveChatActionPanelAction } from "./actions/showLiveChatActionPanelAction";
import { parseShowLiveChatTooltipCommand } from "./actions/showLiveChatTooltipCommand";
import { parseUpdateLiveChatPollAction } from "./actions/updateLiveChatPollAction";
/**
* Parse raw action object and returns Action
*/
export function parseAction(action: YTAction): Action | UnknownAction {
const filteredActions = omitTrackingParams(action);
const type = Object.keys(filteredActions)[0] as keyof typeof filteredActions;
switch (type) {
case "addChatItemAction": {
const parsed = parseAddChatItemAction(action[type]!);
if (parsed) return parsed;
break;
}
case "markChatItemsByAuthorAsDeletedAction":
return parseMarkChatItemsByAuthorAsDeletedAction(action[type]!);
case "markChatItemAsDeletedAction":
return parseMarkChatItemAsDeletedAction(action[type]!);
case "addLiveChatTickerItemAction": {
const parsed = parseAddLiveChatTickerItemAction(action[type]!);
if (parsed) return parsed;
break;
}
case "replaceChatItemAction":
return parseReplaceChatItemAction(action[type]!);
case "addBannerToLiveChatCommand":
return parseAddBannerToLiveChatCommand(action[type]!);
case "removeBannerForLiveChatCommand":
return parseRemoveBannerForLiveChatCommand(action[type]!);
case "showLiveChatTooltipCommand":
return parseShowLiveChatTooltipCommand(action[type]!);
case "showLiveChatActionPanelAction":
const parsed = parseShowLiveChatActionPanelAction(action[type]!);
return parsed;
case "updateLiveChatPollAction":
return parseUpdateLiveChatPollAction(action[type]!);
case "closeLiveChatActionPanelAction":
return parseCloseLiveChatActionPanelAction(action[type]!);
default: {
const _: never = type;
debugLog(
"[action required] Unrecognized action type:",
JSON.stringify(action)
);
}
}
return {
type: "unknown",
payload: action,
} as UnknownAction;
}