Skip to content

Commit

Permalink
feat: new action moderationMessageAction
Browse files Browse the repository at this point in the history
  • Loading branch information
uetchy committed May 26, 2022
1 parent 37ed5f0 commit 80123c7
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
- `mc.getTranscript()`
- Playlist API
- `mc.getPlaylist()`
- New: `ModerationMessageAction` (type: `moderationMessageAction`)

### Improvements

Expand Down
25 changes: 25 additions & 0 deletions src/chat/actions/addChatItemAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ import {
MembershipGiftPurchaseAction,
MembershipGiftRedemptionAction,
MembershipGiftPurchaseTickerContent,
ModerationMessageAction,
} from "../../interfaces/actions";
import {
YTAddChatItemAction,
YTLiveChatMembershipItemRenderer,
YTLiveChatModeChangeMessageRenderer,
YTLiveChatModerationMessageRenderer,
YTLiveChatPaidMessageRenderer,
YTLiveChatPaidStickerRenderer,
YTLiveChatPlaceholderItemRenderer,
Expand Down Expand Up @@ -84,6 +86,9 @@ export function parseAddChatItemAction(payload: YTAddChatItemAction) {
return parseLiveChatSponsorshipsGiftRedemptionAnnouncementRenderer(
renderer
);
} else if ("liveChatModerationMessageRenderer" in item) {
const renderer = item["liveChatModerationMessageRenderer"];
return parseLiveChatModerationMessageRenderer(renderer);
}

debugLog(
Expand Down Expand Up @@ -541,3 +546,23 @@ export function parseLiveChatSponsorshipsGiftRedemptionAnnouncementRenderer(
};
return parsed;
}

// Moderation message
export function parseLiveChatModerationMessageRenderer(
renderer: YTLiveChatModerationMessageRenderer
) {
const id = renderer.id;
const timestampUsec = renderer.timestampUsec;
const timestamp = tsToDate(timestampUsec);

const message = renderer.message.runs;

const parsed: ModerationMessageAction = {
type: "moderationMessageAction",
id,
timestamp,
timestampUsec,
message,
};
return parsed;
}
11 changes: 10 additions & 1 deletion src/interfaces/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ export type Action =
| ShowTooltipAction
| ModeChangeAction
| MembershipGiftPurchaseAction
| MembershipGiftRedemptionAction;
| MembershipGiftRedemptionAction
| ModerationMessageAction;

export interface AddChatItemAction {
type: "addChatItemAction";
Expand Down Expand Up @@ -374,6 +375,14 @@ export interface MembershipGiftRedemptionAction {
authorPhoto: string;
}

export interface ModerationMessageAction {
type: "moderationMessageAction";
id: string;
timestamp: Date;
timestampUsec: string;
message: YTRun[];
}

export interface UnknownAction {
type: "unknown";
payload: unknown;
Expand Down
25 changes: 24 additions & 1 deletion src/interfaces/yt/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,8 @@ export type YTAddChatItemActionItem =
| YTLiveChatViewerEngagementMessageRendererContainer
| YTLiveChatModeChangeMessageRendererContainer
| YTLiveChatSponsorshipsGiftPurchaseAnnouncementRendererContainer
| YTLiveChatSponsorshipsGiftRedemptionAnnouncementRendererContainer;
| YTLiveChatSponsorshipsGiftRedemptionAnnouncementRendererContainer
| YTLiveChatModerationMessageRendererContainer;

export interface YTAddLiveChatTickerItemAction {
item: YTAddLiveChatTickerItem;
Expand Down Expand Up @@ -355,6 +356,10 @@ export interface YTLiveChatSponsorshipsGiftRedemptionAnnouncementRendererContain
liveChatSponsorshipsGiftRedemptionAnnouncementRenderer: YTLiveChatSponsorshipsGiftRedemptionAnnouncementRenderer;
}

export interface YTLiveChatModerationMessageRendererContainer {
liveChatModerationMessageRenderer: YTLiveChatModerationMessageRenderer;
}

// LiveChat Renderers

export interface YTLiveChatTextMessageRenderer {
Expand Down Expand Up @@ -592,6 +597,24 @@ export interface YTLiveChatSponsorshipsGiftRedemptionAnnouncementRenderer {
trackingParams: string;
}

// Moderation message
export interface YTLiveChatModerationMessageRenderer {
message: {
runs: [
{ text: string; bold: true; italics: true },
{
// TODO: find other variants
text: " was hidden by " | " was unhidden by ";
italics: true;
},
{ text: string; bold: true; italics: true },
{ text: "."; italics: true }
];
};
id: string;
timestampUsec: string;
}

// Ticker Renderers

export interface YTAddLiveChatTickerItem {
Expand Down

0 comments on commit 80123c7

Please sign in to comment.