@@ -21,6 +21,8 @@ import { yaml } from "@/src/utils/yaml";
2121import { upsertSlackMessage } from "../gh-desktop-release-notification/upsertSlackMessage" ;
2222import { getSlack , slack } from "@/src/slack" ;
2323import { slackCached } from "@/src/slack/slackCached" ;
24+ import { slackMessageUrlParse } from "../gh-design/slackMessageUrlParse" ;
25+ import { confirm } from "@/lib/utils" ;
2426
2527// yeah, if the bot could ping when updates have been made to a previously-reviewed PR, would be extremely helpful
2628
@@ -139,6 +141,7 @@ if (import.meta.main) {
139141 // const url = "https://github.com/comfyanonymous/ComfyUI/pull/8351";
140142 // await determinePullRequestReviewStatus(url);
141143
144+ // await _cleanSpammyMessages20251117()
142145 await runCorePingTaskFull ( ) ;
143146 // await runCorePingTaskIncremental();
144147 // reviewCommentsCheckpoint()
@@ -325,7 +328,7 @@ async function runCorePingTaskFull() {
325328
326329 // console.log("ready to send slack message to notify @comfy");
327330 // console.log(processedTasks);
328- const tail = `Sent from < https://github.com/Comfy-Org/Comfy-PR/blob/main/app/tasks/coreping/coreping.ts|CorePing.ts> by <@snomiao>` ;
331+ const tail = `Sent from <https://github.com/Comfy-Org/Comfy-PR/blob/main/app/tasks/coreping/coreping.ts|CorePing.ts> by <@snomiao>` ;
329332 const notifyMessage = ! pendingCorePRs . length
330333 ? `Congratulations! All Core/Important PRs are reviewed! 🎉🎉🎉 \n${ tail } `
331334 : `Hey <@comfy>, Here's x${ pendingCorePRs . length } Core/Important PRs waiting your feedback!\n\n${ pendingCorePRs . map ( ( pr ) => pr . statusMsg || `- <${ pr . url } |${ pr . title } > ${ pr . labels } ` ) . join ( "\n" ) } \n\n${ tail } ` ;
@@ -335,7 +338,13 @@ async function runCorePingTaskFull() {
335338 // // send or update slack message
336339 let meta = await Meta . $upsert ( { } ) ;
337340
338- // can only post new message: tz: PST, day: working day + sat, time: 10-12am
341+ const lastMessageTsDate = meta . lastSlackMessage ?. url
342+ ? new Date ( + ( slackMessageUrlParse ( meta . lastSlackMessage . url ) . ts ) * 1000 , )
343+ : null ;
344+
345+ // can only post new message when:
346+ // 1. tz: PST, day: working day + sat, time: 10-12am
347+ // 2. or last message sent time( Note: not edited time ) >23h ago (if have last msg)
339348 const canPostNewMessage = ( ( ) => {
340349 const now = new Date ( ) ;
341350 const pstTime = new Date (
@@ -350,7 +359,10 @@ async function runCorePingTaskFull() {
350359 const isValidTime = hour >= 10 && hour < 12 ;
351360
352361 return isValidDay && isValidTime ;
353- } ) ( ) ;
362+ } ) ( ) && (
363+ ! lastMessageTsDate ||
364+ Date . now ( ) - lastMessageTsDate . getTime ( ) >= 23 * 60 * 60 * 1000
365+ ) ;
354366
355367 const canUpdateExistingMessage =
356368 meta . lastSlackMessage ?. sendAt &&
@@ -487,9 +499,9 @@ async function processPullRequestCorePingTask(
487499}
488500
489501async function _cleanSpammyMessages20251117 ( ) {
490- // list 2025-11-16 2:11 to 3:49 (in HKT)
491- const st = new Date ( '2025-11-16T02 :00:00+0800' ) ;
492- const et = new Date ( '2025-11-16T03:50 :00+0800' ) ;
502+ // list 2025-11-18 2:00 to 3:55 (in HKT)
503+ const st = new Date ( '2025-11-18T02 :00:00+0800' ) ;
504+ const et = new Date ( '2025-11-18T03:55 :00+0800' ) ;
493505 console . log ( `fetch slack messages from ${ st . toISOString ( ) } to ${ et . toISOString ( ) } ` ) ;
494506 // slack.history.list(getslackchannel)
495507 const channel = await pageFlow ( undefined as string | undefined , async ( cursor , limit = 3 ) => {
@@ -510,6 +522,7 @@ async function _cleanSpammyMessages20251117() {
510522 // .log(e => yaml.stringify({}))
511523 . toAtLeastOne ( )
512524
525+ console . log ( 'checking messages sent by ComfyPR-Bot:' , comfyPrBot . id , comfyPrBot . name ) ;
513526 const myspammessages = await pageFlow ( undefined as string | undefined , async ( cursor , limit = 100 ) => {
514527 const resp = await slackCached . conversations . history ( {
515528 channel : channelId ,
@@ -519,13 +532,14 @@ async function _cleanSpammyMessages20251117() {
519532 oldest : String ( ( + st ) / 1000 ) ,
520533 latest : String ( ( + et ) / 1000 ) ,
521534 } )
522- console . log ( `+${ resp . messages ?. length } messages by ${ await sflow ( resp . messages || [ ] )
523- ?. mapMixin ( async e => ( { info : await slackCached . users . info ( { user : e . user || undefined } ) . then ( u => u . user ) } ) )
524- ?. map ( m => String ( m . username || m . info ?. real_name || m . user || '' ) )
525- . filter ( )
526- . join ( ", " )
527- . text ( )
528- } `) ;
535+ console . log ( resp . messages ?. length )
536+ // console.log(`+${resp.messages?.length} messages by ${await sflow(resp.messages || [])
537+ // ?.mapMixin(async e => ({ info: await slackCached.users.info({ user: e.user || undefined }).then(u => u.user) }))
538+ // ?.map(m => String(m.username || m.info?.real_name || m.user || ''))
539+ // .filter()
540+ // .join(", ")
541+ // .text()
542+ // }`);
529543
530544 return { next : resp . response_metadata ?. next_cursor || undefined , data : resp . messages || [ ] } ;
531545 } )
@@ -542,7 +556,6 @@ async function _cleanSpammyMessages20251117() {
542556 // .takeWhile(e => +(e.ts || DIE(`Fatal: msg have no.ts ${e}`)) * 1000 >= (+st))
543557 // .filter(e => e.username)
544558 . filter ( e => e . user === comfyPrBot . id )
545- . forEach ( async e => await slack . chat . delete ( { channel : channelId , ts : e . ts || DIE ( ) } ) )
546559 // throw check
547560 . toArray ( )
548561
@@ -553,4 +566,14 @@ async function _cleanSpammyMessages20251117() {
553566 )
554567 } ) )
555568
556- }
569+ const confirmed = await confirm ( `About to delete ${ myspammessages . length } messages sent by ComfyPR-Bot in #${ channel . name } between ${ st . toISOString ( ) } and ${ et . toISOString ( ) } . Proceed?` ) ;
570+ if ( ! confirmed ) {
571+ console . log ( "Operation cancelled" ) ;
572+ return ;
573+ }
574+
575+ const deletedMessages = await sflow ( myspammessages )
576+ . forEach ( async e => await slack . chat . delete ( { channel : channelId , ts : e . ts || DIE ( ) } ) )
577+ . log ( e => `Deleted message at ${ new Date ( + ( e . ts || DIE ( ) ) * 1000 ) . toISOString ( ) } : ${ e . text ?. replace ( / \n / g, ' ' ) . slice ( 0 , 30 ) } ...` )
578+ . run ( )
579+ }
0 commit comments