1- const { Events, ActivityType } = require ( 'discord.js' ) ;
1+ const { Events, ActivityType, EmbedBuilder } = require ( 'discord.js' ) ;
2+ const cron = require ( 'node-cron' ) ;
3+ const { getNicholasTraveler, getNicholasSandford } = require ( '../helpers/nicholasScraper' ) ;
24
35const STATUSES = [
46 'Pourquoi ? Pour feur.' ,
@@ -20,6 +22,115 @@ function rotateStatus(client) {
2022 client . user . setActivity ( status , { type : ActivityType . Custom } ) ;
2123}
2224
25+ /**
26+ * Posts Nicholas the Traveler update
27+ */
28+ async function postNicholasTraveler ( client ) {
29+ try {
30+ const channelId = process . env . NICHOLAS_CHANNEL_ID ;
31+ if ( ! channelId ) {
32+ console . log ( 'NICHOLAS_CHANNEL_ID not configured, skipping Nicholas the Traveler post' ) ;
33+ return ;
34+ }
35+
36+ const channel = await client . channels . fetch ( channelId ) ;
37+ if ( ! channel ) {
38+ console . error ( 'Nicholas channel not found' ) ;
39+ return ;
40+ }
41+
42+ const data = await getNicholasTraveler ( ) ;
43+
44+ // Build clickable links
45+ const locationValue = data . mapUrl
46+ ? `[${ data . location } ](${ data . mapUrl } )`
47+ : data . location ;
48+ const itemValue = data . itemUrl
49+ ? `[${ data . item } ](${ data . itemUrl } )`
50+ : data . item ;
51+
52+ const embed = new EmbedBuilder ( )
53+ . setTitle ( '🧳 Nicholas le Voyageur' )
54+ . setColor ( 0x00AE86 )
55+ . addFields (
56+ { name : '📍 Localisation' , value : locationValue , inline : true } ,
57+ { name : '📦 Objet demandé' , value : itemValue , inline : true } ,
58+ { name : '🔢 Quantité' , value : `${ data . quantity } par cadeau` , inline : true } ,
59+ )
60+ . setFooter ( { text : 'Mise à jour hebdomadaire - Tous les lundis à 15:00 UTC' } )
61+ . setTimestamp ( ) ;
62+
63+ await channel . send ( { embeds : [ embed ] } ) ;
64+ console . log ( 'Posted Nicholas the Traveler update' ) ;
65+ } catch ( error ) {
66+ console . error ( 'Error posting Nicholas the Traveler update:' , error ) ;
67+ }
68+ }
69+
70+ /**
71+ * Posts Nicholas Sandford update
72+ */
73+ async function postNicholasSandford ( client ) {
74+ try {
75+ const channelId = process . env . NICHOLAS_CHANNEL_ID ;
76+ if ( ! channelId ) {
77+ console . log ( 'NICHOLAS_CHANNEL_ID not configured, skipping Nicholas Sandford post' ) ;
78+ return ;
79+ }
80+
81+ const channel = await client . channels . fetch ( channelId ) ;
82+ if ( ! channel ) {
83+ console . error ( 'Nicholas channel not found' ) ;
84+ return ;
85+ }
86+
87+ const data = await getNicholasSandford ( ) ;
88+
89+ // Build clickable link for item
90+ const itemValue = data . itemUrl
91+ ? `[${ data . item } ](${ data . itemUrl } )`
92+ : data . item ;
93+
94+ const embed = new EmbedBuilder ( )
95+ . setTitle ( '🏹 Nicholas Sandford' )
96+ . setColor ( 0xFF6B35 )
97+ . addFields (
98+ { name : '📦 Objet demandé' , value : itemValue , inline : true } ,
99+ { name : '🔢 Quantité' , value : `${ data . quantity } objets` , inline : true } ,
100+ )
101+ . setFooter ( { text : 'Mise à jour quotidienne - Tous les jours à 07:00 UTC' } )
102+ . setTimestamp ( ) ;
103+
104+ await channel . send ( { embeds : [ embed ] } ) ;
105+ console . log ( 'Posted Nicholas Sandford update' ) ;
106+ } catch ( error ) {
107+ console . error ( 'Error posting Nicholas Sandford update:' , error ) ;
108+ }
109+ }
110+
111+ /**
112+ * Setup cron jobs for Nicholas posts
113+ */
114+ function setupNicholasCronJobs ( client ) {
115+ // Nicholas the Traveler: Every Monday at 15:05 UTC
116+ cron . schedule ( '5 15 * * 1' , ( ) => {
117+ console . log ( 'Running Nicholas the Traveler cron job' ) ;
118+ postNicholasTraveler ( client ) ;
119+ } , {
120+ timezone : 'UTC' ,
121+ } ) ;
122+
123+ // Nicholas Sandford: Every day at 07:05 UTC
124+ cron . schedule ( '5 7 * * *' , ( ) => {
125+ console . log ( 'Running Nicholas Sandford cron job' ) ;
126+ postNicholasSandford ( client ) ;
127+ } , {
128+ timezone : 'UTC' ,
129+ } ) ;
130+
131+ console . log ( 'Nicholas cron jobs scheduled' ) ;
132+ }
133+
23134module . exports = {
24135 name : Events . ClientReady ,
25136 once : true ,
@@ -28,5 +139,8 @@ module.exports = {
28139
29140 rotateStatus ( client ) ;
30141 setInterval ( ( ) => rotateStatus ( client ) , 5 * 60 * 1000 ) ; // toutes les 5 min
142+
143+ // Setup Nicholas auto-posting
144+ setupNicholasCronJobs ( client ) ;
31145 } ,
32146} ;
0 commit comments