Skip to content

Commit

Permalink
Ignore some action with max age
Browse files Browse the repository at this point in the history
  • Loading branch information
HitomaruKonpaku committed Sep 24, 2024
1 parent 66678b3 commit 833e5c6
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions apps/back-end/src/module/youtube/base/base-action-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Track, TrackService } from '@app/track'
import { UserFilter, UserFilterRepository, UserFilterType, UserSourceType } from '@app/user'
import { YoutubeChatAction, YoutubeChatActionJobData, YoutubeChatUtil } from '@app/youtube'
import { ModuleRef } from '@nestjs/core'
import { NumberUtil } from '@shared/util/number.util'
import { bold, inlineCode } from 'discord.js'
import {
AddBannerAction,
Expand Down Expand Up @@ -104,12 +105,13 @@ export abstract class BaseActionHandler<T1 extends HandlerAction, T2 extends Pro
if (!this.data.video.isLive && !track.allowReplay) {
return
}
// if (this.data.video.isLive && action.timestamp) {
// const maxAge = NumberUtil.parse(process.env.YOUTUBE_ACTION_MAX_AGE, 2 * 60) * 1000
// if (action.timestamp.getTime() + maxAge < Date.now()) {
// return
// }
// }
if (this.data.video.isLive && action.timestamp) {
const age = Date.now() - action.timestamp.getTime()
const maxAge = NumberUtil.parse(process.env.YOUTUBE_ACTION_MAX_AGE, 3600) * 1000
if (age > maxAge) {
return
}
}
if (this.data.video.isMembersOnly && !track.allowMemberChat) {
return
}
Expand Down Expand Up @@ -142,16 +144,22 @@ export abstract class BaseActionHandler<T1 extends HandlerAction, T2 extends Pro

const icons = this.getIcons(track)
const name = inlineCode(YoutubeChatUtil.getAuthorName(action))
const displayHeader = [
YoutubeChatHandlerUtil.getSrcHyperlink(this.data),
icons.join(' '),
name,
].filter((v) => v).join(' ')
const displayMessage = message
? ` ${bold(inlineCode(message))}`
? `${bold(inlineCode(message))}`
: ''

let primaryLine = displayHeader
if (displayMessage) {
primaryLine += `: ${displayMessage}`
}

const lines = [
`${[
YoutubeChatHandlerUtil.getSrcHyperlink(this.data),
icons.join(' '),
name,
].filter((v) => v).join(' ')}:${displayMessage}`,
primaryLine,
]

if (!YoutubeChatUtil.isAddBannerAction(action) && !track.sourceId) {
Expand Down

0 comments on commit 833e5c6

Please sign in to comment.