@@ -46,7 +46,11 @@ export default new Cron({
46
46
const embed = new EmbedBuilder ( )
47
47
. setTitle ( `GoG - ${ game . title } ` )
48
48
. setURL ( 'https://www.gog.com/#giveaway' )
49
- . setDescription ( game . description )
49
+ . setDescription (
50
+ game . description . length > 1000
51
+ ? game . description . slice ( 0 , 999 ) + '…'
52
+ : game . description ,
53
+ )
50
54
. setImage ( game . banner )
51
55
. addFields ( {
52
56
name : 'URL du jeu' ,
@@ -112,18 +116,20 @@ export async function getOfferedGame(logger: Logger): Promise<Game | null> {
112
116
if ( ! homeBody ) return null ;
113
117
const html = parse ( homeBody ) ;
114
118
if ( ! html ) return null ;
115
- const SEOLink = html . querySelector ( 'a#giveaway' ) ;
119
+ const giveawayNode = html . querySelector ( '#giveaway' ) ;
120
+ if ( ! giveawayNode ) return null ;
121
+ const SEOLink = giveawayNode . querySelector ( 'a.giveaway__overlay-link' ) ;
116
122
if ( ! SEOLink ) return null ;
123
+ const gameURL = SEOLink . getAttribute ( 'href' ) ;
124
+ if ( ! gameURL ) return null ;
125
+
117
126
const endTimestamp = Number (
118
127
html
119
128
. querySelector ( '.giveaway-banner__footer gog-countdown-timer' )
120
129
?. getAttribute ( 'end-date' ) ,
121
130
) ;
122
131
123
- const { body : gameBody } = await got < string > (
124
- `https://www.gog.com${ SEOLink . getAttribute ( 'ng-href' ) } ` ,
125
- GOG_GOT_OPTIONS ,
126
- ) ;
132
+ const { body : gameBody } = await got < string > ( gameURL , GOG_GOT_OPTIONS ) ;
127
133
if ( ! gameBody ) return null ;
128
134
const gameHTML = parse ( gameBody ) ;
129
135
if ( ! gameHTML ) return null ;
@@ -135,15 +141,16 @@ export async function getOfferedGame(logger: Logger): Promise<Game | null> {
135
141
if ( ! gameJSON ) {
136
142
// the gift link redirect to incorrect page
137
143
const title =
138
- SEOLink . querySelector ( '.giveaway-banner__title' ) ?. textContent ??
139
- SEOLink . getAttribute ( 'giveaway-banner-id' ) ??
144
+ giveawayNode . querySelector ( '.giveaway-banner__title' ) ?. textContent ??
145
+ giveawayNode . getAttribute ( 'giveaway-banner-id' ) ??
140
146
'' ;
141
147
const description =
142
- SEOLink . querySelector ( '.giveaway-banner__description' ) ?. textContent ?? '' ;
148
+ giveawayNode . querySelector ( '.giveaway-banner__description' )
149
+ ?. textContent ?? '' ;
143
150
const srcset =
144
- SEOLink . querySelector (
145
- '.giveaway-banner__image source[type="image/png"]' ,
146
- ) ?. getAttribute ( 'srcset' ) ?? '' ;
151
+ giveawayNode
152
+ . querySelector ( '.giveaway-banner__image source[type="image/png"]' )
153
+ ?. getAttribute ( 'srcset' ) ?? '' ;
147
154
/*
148
155
* srcset="
149
156
* //images-1.gog-statics.com/c26a3d08d01005d92fbc4b658ab226fc5de374d3746f313a01c83e615cc066c1_giveaway_banner_logo_502_2x.png 2x,
@@ -172,8 +179,9 @@ export async function getOfferedGame(logger: Logger): Promise<Game | null> {
172
179
}
173
180
174
181
const description =
175
- gameHTML . querySelector ( '.content-summary-item__description' ) ?. textContent ??
176
- '' ;
182
+ gameHTML
183
+ . querySelector ( '.content-summary-section .description' )
184
+ ?. textContent ?. trim ( ) ?? '' ;
177
185
const banner =
178
186
gameHTML
179
187
. querySelector ( 'head meta[property="og:image"]' )
@@ -185,15 +193,27 @@ export async function getOfferedGame(logger: Logger): Promise<Game | null> {
185
193
) ;
186
194
187
195
const rating = gameJSON . aggregateRating ?. ratingValue ?? '?' ;
196
+ let link : string = gameJSON . offers [ 0 ] . url ;
197
+ {
198
+ const searchIndex = link . indexOf ( '?' ) ;
199
+ if ( searchIndex !== - 1 ) {
200
+ link = link . slice ( 0 , searchIndex ) ;
201
+ }
202
+ }
203
+
204
+ const frOffer = gameJSON . offers . find (
205
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
206
+ ( o : any ) => new URL ( o . url ) . searchParams . get ( 'countryCode' ) === 'FR' ,
207
+ ) ;
188
208
189
209
return {
190
210
title : gameJSON . name . trim ( ) ,
191
211
description : decode ( description ) ,
192
212
// link: 'https://www.gog.com/fr#giveaway',
193
- link : gameJSON . offers . url ,
213
+ link,
194
214
thumbnail : gameJSON . image ,
195
215
banner,
196
- originalPrice : gameJSON . offers . price ,
216
+ originalPrice : ` ${ frOffer . price } €` ,
197
217
discountEndDate : new Date ( endTimestamp ) ,
198
218
rating : `${ rating } / 5` ,
199
219
} ;
0 commit comments