Skip to content
This repository has been archived by the owner on Feb 11, 2023. It is now read-only.

Commit

Permalink
Fix no dynamics error
Browse files Browse the repository at this point in the history
  • Loading branch information
luooooob committed Nov 30, 2021
1 parent 3d6d266 commit 66b82cf
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ export const activate = (context: vscode.ExtensionContext) => {
const bilibiliLiveStatusNotificationsEnabled = configuration.get("bilibiliLiveStatus.enabled", false)
const douyinVideosNotificationsEnabled = configuration.get("douyinVideos.enabled", false)

const bilibiliDynamicsCronExpression = "*/2 * * * *"
const bilibiliLiveStatusCronExpression = "*/2 * * * *"
const douyinVideosCronExpression = "*/2 * * * *"
const bilibiliDynamicsCronExpression = "*/30 * * * * *"
const bilibiliLiveStatusCronExpression = "*/30 * * * * *"
const douyinVideosCronExpression = "*/30 * * * * *"

const bilibiliUsers: BilibiliUser[] = asoulMembers
.reduce((users, { bilibiliId, nickname }) => {
Expand All @@ -35,17 +35,17 @@ export const activate = (context: vscode.ExtensionContext) => {
}, [] as DouyinUser[])

const bilibiliDynamicsNotificationsTask = cron.schedule(bilibiliDynamicsCronExpression, () => {
console.log(Date.now().toLocaleString())
bilibiliUsers.map(async ({ bilibiliId, nickname }) => {
try {
const oldDynamicIdsKey = `old-dynamic-ids-${bilibiliId}`
const res = await bilibiliDynamics.requestDynamics(bilibiliId)
const oldDynamicIds = context.globalState.get<string[]>(oldDynamicIdsKey) ?? []
const newDynamics = bilibiliDynamics
.getDynamicsFromResponse(res, nickname)
.filter(({ dynamicId }) => oldDynamicIds.length > 0 && !oldDynamicIds.includes(dynamicId))
const currentDynamics = bilibiliDynamics.getDynamicsFromResponse(res, nickname)
const newDynamics = currentDynamics.filter(({ dynamicId }) => oldDynamicIds.length > 0 && !oldDynamicIds.includes(dynamicId))
newDynamics.forEach(({ message, commands }) => createNotification(message, ...commands))
const newDynamicIds = newDynamics.map(({ dynamicId }) => dynamicId)
context.globalState.update(oldDynamicIdsKey, [...oldDynamicIds, ...newDynamicIds])
const currentDynamicIds = currentDynamics.map(({ dynamicId }) => dynamicId)
context.globalState.update(oldDynamicIdsKey, [...oldDynamicIds, ...currentDynamicIds])
} catch (err) {
console.log(err)
}
Expand Down Expand Up @@ -76,12 +76,11 @@ export const activate = (context: vscode.ExtensionContext) => {
const oldVideoIdsKey = `old-video-ids-${douyinId}`
const res = await douyinVideos.requestVideos(douyinId)
const oldVideoIds = context.globalState.get<string[]>(oldVideoIdsKey) ?? []
const newVideos = douyinVideos
.getVideosFromResponse(res, nickname)
.filter(({ videoId }) => oldVideoIds.length > 0 && !oldVideoIds.includes(videoId))
const currentVideos = douyinVideos.getVideosFromResponse(res, nickname)
const newVideos = currentVideos.filter(({ videoId }) => oldVideoIds.length > 0 && !oldVideoIds.includes(videoId))
newVideos.forEach(({ message, commands }) => createNotification(message, ...commands))
const newVideoIds = newVideos.map(({ videoId }) => videoId)
context.globalState.update(oldVideoIdsKey, [...oldVideoIds, ...newVideoIds])
const currentVideoIds = currentVideos.map(({ videoId }) => videoId)
context.globalState.update(oldVideoIdsKey, [...oldVideoIds, ...currentVideoIds])
} catch (err) {
console.log(err)
}
Expand Down

0 comments on commit 66b82cf

Please sign in to comment.