1+ 'use.strict'
2+
3+ const axios = require ( 'axios' ) ,
4+ { identity, clientId } = require ( '../config.json' ) ,
5+ { getCurrentDatetime } = require ( '../utils.js' ) ;
6+
7+ const params = {
8+ headers : {
9+ Authorization : `Bearer ${ identity . password } ` ,
10+ 'Client-ID' : clientId
11+ }
12+ } ;
13+
14+ module . exports = {
15+ data : {
16+ name : 'followage' ,
17+ description : 'a dynamic followage'
18+ } ,
19+ async execute ( client , channel , message , userstate ) {
20+ if ( userstate . username === 'daftmob' ) {
21+ client . reply ( channel , `debilus...` , userstate . id )
22+ . catch ( e => console . log ( e ) ) ;
23+ return ;
24+ } ;
25+
26+ let fe = await axios . get ( `https://api.twitch.tv/helix/channels/followed?user_id=${ userstate . id } ` + params )
27+ . catch ( err => { console . log ( `[${ getCurrentDatetime ( 'comm' ) } ] Error FETCH ${ err } ` ) ; } ) ,
28+ timeSince = new Date ( fe . data . data [ 0 ] . followed_at ) . toLocaleString ( 'fr-FR' , { timeZone : 'Europe/Paris' } ) ,
29+ day = timeSince . split ( '/' ) [ 0 ] ,
30+ months = timeSince . split ( '/' ) [ 1 ] ,
31+ years = new Date ( fe . data . data [ 0 ] . followed_at ) . getUTCFullYear ( ) ;
32+
33+ switch ( months ) {
34+ case '01' :
35+ months = months . replace ( '01' , 'janvier' ) ;
36+ break ;
37+ case '02' :
38+ months = months . replace ( '02' , 'février' ) ;
39+ break ;
40+ case '03' :
41+ months = months . replace ( '03' , 'mars' ) ;
42+ break ;
43+ case '04' :
44+ months = months . replace ( '04' , 'avril' ) ;
45+ break ;
46+ case '05' :
47+ months = months . replace ( '05' , 'mai' ) ;
48+ break ;
49+ case '06' :
50+ months = months . replace ( '06' , 'juin' ) ;
51+ break ;
52+ case '07' :
53+ months = months . replace ( '07' , 'juillet' ) ;
54+ break ;
55+ case '08' :
56+ months = months . replace ( '08' , 'août' ) ;
57+ break ;
58+ case '09' :
59+ months = months . replace ( '09' , 'septembre' ) ;
60+ break ;
61+ case '10' :
62+ months = months . replace ( '10' , 'octobre' ) ;
63+ break ;
64+ case '11' :
65+ months = months . replace ( '11' , 'novembre' ) ;
66+ break ;
67+ case '12' :
68+ months = months . replace ( '12' , 'décembre' ) ;
69+ break ;
70+ } ;
71+
72+ client . reply ( channel , `${ userstate . username } follow le ptit daft depuis ${ day } ${ months } ${ years } ` , userstate . id )
73+ . catch ( e => console . log ( e ) ) ;
74+ }
75+ } ;
0 commit comments