Skip to content

Commit a483ddc

Browse files
committed
Enhance draft clip creation by incorporating stream delay
This commit updates the draft clip creation logic to account for stream delay when scheduling tasks. The delay for creating clips during the draft and strategy time events is now dynamically adjusted based on the stream delay, improving the accuracy of clip timing.
1 parent 19fdb4b commit a483ddc

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

packages/dota/src/dota/events/gsi-events/map.game_state.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { getTwitchAPI, logger } from '@dotabod/shared-utils'
22
import { DBSettings, getValueOrDefault } from '../../../settings.js'
33
import { is8500Plus } from '../../../utils/index.js'
4+
import { getStreamDelay } from '../../getStreamDelay.js'
45
import { type allStates, draftStartByMatchId } from '../../lib/consts.js'
56
import { delayedQueue } from '../../lib/DelayedQueue.js'
67
import { isPlayingMatch } from '../../lib/isPlayingMatch.js'
@@ -54,10 +55,12 @@ eventHandler.registerEvent('map:game_state', {
5455
// Create a clip when the draft starts to get a list of players
5556
if ('DOTA_GAMERULES_STATE_PLAYER_DRAFT' === gameState) {
5657
draftStartByMatchId.set(dotaClient.client.gsi?.map?.matchid || '', true)
57-
logger.info('[Draft Clip] Draft started, creating clip in 46 seconds', logContext)
58+
const DRAFT_CLIP_DELAY_MS = 46000 // 46 seconds
59+
const streamDelay = getStreamDelay(dotaClient.client.settings, dotaClient.client.subscription)
60+
logger.info('[Draft Clip] Draft started, creating clip in 46 seconds + stream delay', logContext)
5861

5962
// Delay to ensure the draft has started
60-
delayedQueue.addTask(46000, async () => {
63+
delayedQueue.addTask(DRAFT_CLIP_DELAY_MS + streamDelay, async () => {
6164
try {
6265
const api = await getTwitchAPI(accountId)
6366
const clipId = await api.clips.createClip({
@@ -113,8 +116,9 @@ eventHandler.registerEvent('map:game_state', {
113116

114117
if ('DOTA_GAMERULES_STATE_STRATEGY_TIME' === gameState) {
115118
const CLIP_DELAY_MS = 50000 // 50 seconds
119+
const streamDelay = getStreamDelay(dotaClient.client.settings, dotaClient.client.subscription)
116120

117-
delayedQueue.addTask(CLIP_DELAY_MS, async () => {
121+
delayedQueue.addTask(CLIP_DELAY_MS + streamDelay, async () => {
118122
try {
119123
const api = await getTwitchAPI(accountId)
120124
const clipId = await api.clips.createClip({

0 commit comments

Comments
 (0)