@@ -12,7 +12,7 @@ async function fetchData(auth, sheetsID) {
1212
1313 const sheets = google . sheets ( { version : 'v4' , auth } ) ;
1414 const spreadsheetId = sheetsID ;
15- const range = 'Sheet1!A2:J ' ;
15+ const range = 'Sheet1!A2:K ' ;
1616
1717 try {
1818 const response = await sheets . spreadsheets . values . get ( {
@@ -26,7 +26,7 @@ async function fetchData(auth, sheetsID) {
2626 return [ ] ;
2727 }
2828
29- return rows . map ( ( [ date , time , type , title , description , location , eventTime , url , thumbnailURL , imageURL ] ) => ( {
29+ return rows . map ( ( [ date , time , type , title , description , location , eventTime , url , thumbnailURL , imageURL , severity ] ) => ( {
3030 date,
3131 time,
3232 type : Number ( type ) ,
@@ -37,6 +37,7 @@ async function fetchData(auth, sheetsID) {
3737 url,
3838 thumbnailURL,
3939 imageURL,
40+ severity,
4041 } ) ) ;
4142 }
4243 catch ( error ) {
@@ -55,15 +56,36 @@ async function scheduleAnnouncements() {
5556 const channel = await client . channels . fetch ( config . announcementsChannelID ) ;
5657 const announcements = await fetchData ( auth , config . sheetsID ) ;
5758
58- announcements . forEach ( ( { date, time, type, title, description, location, eventTime, url, thumbnailURL, imageURL } ) => {
59+ announcements . forEach ( ( { date, time, type, title, description, location, eventTime, url, thumbnailURL, imageURL, severity } ) => {
5960
6061 const [ hour , minute ] = time . split ( ':' ) . map ( Number ) ;
6162
6263 schedule . scheduleJob ( { year : new Date ( date ) . getFullYear ( ) , month : new Date ( date ) . getMonth ( ) , day : new Date ( date ) . getDate ( ) , hour, minute } , ( ) => {
6364
6465 // type 1 for plain text
6566 if ( type == 1 ) {
66- channel . send ( `${ title } : ${ description } . [${ location } , ${ eventTime } ]` ) ;
67+ let message = '' ;
68+ if ( title ) {
69+ message += `**${ title } **` ;
70+ if ( description ) { message += `: ${ description } ` ; }
71+ } else if ( description ) { message += `${ description } ` ; }
72+ let locationTime = '' ;
73+ if ( location ) { locationTime += `*${ location } *` ; }
74+ if ( eventTime ) {
75+ if ( location ) { locationTime += `, *${ eventTime } *` ; }
76+ else { ocationTime += `*${ eventTime } *` ; }
77+ }
78+ if ( locationTime ) { message += `[${ locationTime } ]` ; }
79+
80+
81+ if ( severity == 1 ) {
82+ channel . send ( `<@&${ config . announcementsRoleID } > - ${ message } ` ) ;
83+ } else if ( severity == 2 ) {
84+ channel . send ( `@everyone - ${ message } ` ) ;
85+ } else {
86+ channel . send ( message ) ;
87+ }
88+
6789 }
6890
6991 // type 2 for embed message
@@ -72,18 +94,24 @@ async function scheduleAnnouncements() {
7294 const embed = new EmbedBuilder ( )
7395 . setColor ( '#BC271B' )
7496 . setTitle ( title )
75- . setDescription ( description )
97+ . setDescription ( description ) ;
7698
7799 if ( url ) { embed . setURL ( url ) ; }
78- if ( thumbnailURL ) { embed . setThumbnail ( thumbnailURL ) ; }
100+ if ( thumbnailURL ) { embed . setThumbnail ( thumbnailURL ) ; }
79101 if ( imageURL ) { embed . setImage ( imageURL ) ; }
80-
102+
81103 const fields = [ ] ;
82104 if ( location ) { fields . push ( { name : 'Location' , value : location , inline : true } ) ; }
83- if ( time ) { fields . push ( { name : 'Time' , value : time , inline : true } ) ; }
105+ if ( time ) { fields . push ( { name : 'Time' , value : eventTime , inline : true } ) ; }
84106 if ( fields . length > 0 ) { embed . addFields ( fields ) ; }
85107
86- channel . send ( { embeds : [ embed ] } ) ;
108+ if ( severity == 1 ) {
109+ channel . send ( { content : `<@&${ config . announcementsRoleID } >` , embeds : [ embed ] } ) ;
110+ } else if ( severity == 2 ) {
111+ channel . send ( { content : "@everyone" , embeds : [ embed ] } ) ;
112+ } else {
113+ channel . send ( { embeds : [ embed ] } ) ;
114+ }
87115 }
88116 } ) ;
89117
@@ -98,7 +126,7 @@ async function scheduleAnnouncements() {
98126
99127client . once ( 'ready' , ( ) => {
100128 console . log ( `Logged in as ${ client . user . tag } !` ) ;
101- scheduleAnnouncements ( ) ;
129+ scheduleAnnouncements ( ) ;
102130} ) ;
103131
104132client . login ( config . discordBotToken ) ;
0 commit comments