@@ -2,48 +2,42 @@ import { execWithContext } from "../lib/executor";
22import { REACTION } from "../lib/types" ;
33
44await execWithContext ( async ( ctx ) => {
5- const now = new Date ( ) ;
6- const yesterday19 = new Date ( now ) ;
7- // TODO: UTC+9 以外の TZ で実行された時動かなそう
8- yesterday19 . setDate ( now . getDate ( ) - 1 ) ;
9- yesterday19 . setHours ( 19 , 0 , 0 , 0 ) ;
5+ const now = new Date ( ) ;
6+ const yesterday19 = new Date ( now ) ;
7+ // TODO: UTC+9 以外の TZ で実行された時動かなそう
8+ yesterday19 . setDate ( now . getDate ( ) - 1 ) ;
9+ yesterday19 . setHours ( 19 , 0 , 0 , 0 ) ;
1010
11- const msgs = await ctx . channel . messages . fetch ( { limit : 100 } ) ;
12- const pollMsg = msgs . find (
13- ( m ) =>
14- m . author . id === ctx . client . user ?. id &&
15- m . createdTimestamp >= yesterday19 . getTime ( ) &&
16- m . content . startsWith ( "[明日の朝活意思確認]" ) ,
17- ) ;
18- if ( ! pollMsg ) {
19- console . error ( "昨日のアンケートが見つかりません" ) ;
20- return ;
21- }
11+ const msgs = await ctx . channel . messages . fetch ( { limit : 100 } ) ;
12+ const pollMsg = msgs . find (
13+ ( m ) =>
14+ m . author . id === ctx . client . user ?. id &&
15+ m . createdTimestamp >= yesterday19 . getTime ( ) &&
16+ m . content . startsWith ( "[明日の朝活意思確認]" ) ,
17+ ) ;
18+ if ( ! pollMsg ) {
19+ console . error ( "昨日のアンケートが見つかりません" ) ;
20+ return ;
21+ }
2222
23- const reaction = pollMsg . reactions . cache . get ( REACTION ) ;
24- if ( ! reaction ) return console . error ( "ERROR: リアクション無し (0)" ) ; // ボットはいるはず
25- const users = await reaction . users . fetch ( ) ;
26- const targets = users . filter ( ( u ) => ! u . bot ) . map ( ( u ) => u . id ) ;
27- if ( ! targets . length ) {
28- console . log ( "OK: ユーザーのリアクション無し" ) ;
29- return ;
30- }
23+ const reaction = pollMsg . reactions . cache . get ( REACTION ) ;
24+ if ( ! reaction ) return console . error ( "ERROR: リアクション無し (0)" ) ; // ボットはいるはず
25+ const users = await reaction . users . fetch ( ) ;
26+ const targets = users . filter ( ( u ) => ! u . bot ) . map ( ( u ) => u . id ) ;
27+ if ( ! targets . length ) {
28+ console . log ( "OK: ユーザーのリアクション無し" ) ;
29+ return ;
30+ }
3131
32- // TODO: 同上; UTC+9 以外の TZ で実行された時動かなそう
33- const today5 = new Date ( now ) . setHours ( 5 , 0 , 0 , 0 ) ; // 5 時より前は寝る前のメッセージとする
34- const todayMsgs = await ctx . channel . messages . fetch ( { limit : 100 } ) ;
35- const greeted = new Set (
36- todayMsgs
37- . filter ( ( m ) => m . createdTimestamp >= today5 )
38- . map ( ( m ) => m . author . id ) ,
39- ) ;
32+ // TODO: 同上; UTC+9 以外の TZ で実行された時動かなそう
33+ const today5 = new Date ( now ) . setHours ( 5 , 0 , 0 , 0 ) ; // 5 時より前は寝る前のメッセージとする
34+ const todayMsgs = await ctx . channel . messages . fetch ( { limit : 100 } ) ;
35+ const greeted = new Set ( todayMsgs . filter ( ( m ) => m . createdTimestamp >= today5 ) . map ( ( m ) => m . author . id ) ) ;
4036
41- const sleepyheads = targets . filter ( ( id ) => ! greeted . has ( id ) ) ;
42- if ( sleepyheads . length ) {
43- await ctx . channel . send (
44- `${ sleepyheads . map ( ( id ) => `<@${ id } >` ) . join ( " " ) } **8 時に起きられない人、厳しいって**` ,
45- ) ;
46- } else {
47- await ctx . channel . send ( "全員が起床済みでした 🎉" ) ;
48- }
37+ const sleepyheads = targets . filter ( ( id ) => ! greeted . has ( id ) ) ;
38+ if ( sleepyheads . length ) {
39+ await ctx . channel . send ( `${ sleepyheads . map ( ( id ) => `<@${ id } >` ) . join ( " " ) } **8 時に起きられない人、厳しいって**` ) ;
40+ } else {
41+ await ctx . channel . send ( "全員が起床済みでした 🎉" ) ;
42+ }
4943} ) ;
0 commit comments