@@ -38,8 +38,139 @@ const data = new SlashCommandBuilder()
38
38
option
39
39
. setName ( '닉네임' )
40
40
. setRequired ( true )
41
- . setDescription ( '전적을 찾으려는 닉네임을 입력해주세요' ) )
42
- ) ;
41
+ . setDescription ( '전적을 찾으려는 닉네임을 입력해주세요' )
42
+ . setAutocomplete ( true )
43
+ )
44
+ . addStringOption ( option =>
45
+ option
46
+ . setName ( '모드' )
47
+ . setDescription ( '전적을 찾으려는 모드를 입력해주세요' )
48
+ . addChoices (
49
+ { name : '솔로' , value :'solo' } ,
50
+ { name : '듀오' , value : 'duo' } ,
51
+ { name : '스쿼드' , value : 'squad' } ,
52
+ { name : '솔로-FFP' , value : 'solo-fpp' } ,
53
+ { name : '듀오-FFP' , value : 'duo-fpp' } ,
54
+ { name : '스쿼드-FFP' , value : 'squad-fpp' }
55
+ )
56
+ . setRequired ( false )
57
+ )
58
+ ) ;
59
+
60
+
61
+
62
+ //배그 전적 정보 가져오기
63
+ async function getPlayerData ( nickName , playerID , mode , season ) {
64
+ let embedData ;
65
+ await fetch ( `https://api.pubg.com/shards/steam/players/${ playerID } /seasons/lifetime?filter[gamepad]=false` , {
66
+ method : 'GET' ,
67
+ headers : {
68
+ "Authorization" : "Bearer " + process . env . PUBG_KEY ,
69
+ "Accept" : "application/vnd.api+json"
70
+ }
71
+ } )
72
+ . then ( json => json . json ( ) )
73
+ . then ( async json => {
74
+ let kills = 0 , deaths = 0 , assists = 0 , wins = 0 , top10s = 0 , roundsPlayed = 0 , headshotKills = 0 , damageDealt = 0 , DBNOs = 0 , teamKills = 0 , timeSurvived = 0 , roadKills = 0 , longestKill = 0 , vehicleDestroys = 0 , revives = 0 , boosts = 0 , heals = 0 , weaponsAcquired = 0
75
+ if ( mode === null ) {
76
+ for ( const key in json . data . attributes . gameModeStats ) {
77
+ kills += json . data . attributes . gameModeStats [ key ] . kills ;
78
+ deaths += json . data . attributes . gameModeStats [ key ] . deaths ;
79
+ assists += json . data . attributes . gameModeStats [ key ] . assists ;
80
+ wins += json . data . attributes . gameModeStats [ key ] . wins ;
81
+ top10s += json . data . attributes . gameModeStats [ key ] . top10s ;
82
+ roundsPlayed += json . data . attributes . gameModeStats [ key ] . roundsPlayed ;
83
+ headshotKills += json . data . attributes . gameModeStats [ key ] . headshotKills ;
84
+ damageDealt += json . data . attributes . gameModeStats [ key ] . damageDealt ;
85
+ DBNOs += json . data . attributes . gameModeStats [ key ] . dBNOs ;
86
+ teamKills += json . data . attributes . gameModeStats [ key ] . teamKills ;
87
+ timeSurvived += json . data . attributes . gameModeStats [ key ] . timeSurvived ;
88
+ roadKills += json . data . attributes . gameModeStats [ key ] . roadKills ;
89
+ boosts += json . data . attributes . gameModeStats [ key ] . boosts ;
90
+ heals += json . data . attributes . gameModeStats [ key ] . heals ;
91
+ weaponsAcquired += json . data . attributes . gameModeStats [ key ] . weaponsAcquired ;
92
+ revives += json . data . attributes . gameModeStats [ key ] . revives ;
93
+ vehicleDestroys += json . data . attributes . gameModeStats [ key ] . vehicleDestroys ;
94
+ }
95
+ embedData = {
96
+ mode : "lifetime" ,
97
+ kills : kills ,
98
+ deaths : deaths ,
99
+ assists : assists ,
100
+ wins : wins ,
101
+ top10s : top10s ,
102
+ roundsPlayed : roundsPlayed ,
103
+ headshotKills : headshotKills ,
104
+ damageDealt : damageDealt ,
105
+ DBNOs : DBNOs ,
106
+ teamKills : teamKills ,
107
+ timeSurvived : timeSurvived ,
108
+ roadKills : roadKills ,
109
+ boosts : boosts ,
110
+ heals : heals ,
111
+ weaponsAcquired : weaponsAcquired ,
112
+ revives : revives ,
113
+ vehicleDestroys : vehicleDestroys
114
+ }
115
+ } else {
116
+ embedData = {
117
+ mode : mode ,
118
+ kills : json . data . attributes . gameModeStats [ mode ] . kills ,
119
+ deaths : json . data . attributes . gameModeStats [ mode ] . deaths ,
120
+ assists : json . data . attributes . gameModeStats [ mode ] . assists ,
121
+ wins : json . data . attributes . gameModeStats [ mode ] . wins ,
122
+ top10s : json . data . attributes . gameModeStats [ mode ] . top10s ,
123
+ roundsPlayed : json . data . attributes . gameModeStats [ mode ] . roundsPlayed ,
124
+ headshotKills : json . data . attributes . gameModeStats [ mode ] . headshotKills ,
125
+ damageDealt : json . data . attributes . gameModeStats [ mode ] . damageDealt ,
126
+ DBNOs : json . data . attributes . gameModeStats [ mode ] . dBNOs ,
127
+ teamKills : json . data . attributes . gameModeStats [ mode ] . teamKills ,
128
+ timeSurvived : json . data . attributes . gameModeStats [ mode ] . timeSurvived ,
129
+ roadKills : json . data . attributes . gameModeStats [ mode ] . roadKills ,
130
+ boosts : json . data . attributes . gameModeStats [ mode ] . boosts ,
131
+ heals : json . data . attributes . gameModeStats [ mode ] . heals ,
132
+ weaponsAcquired : json . data . attributes . gameModeStats [ mode ] . weaponsAcquired ,
133
+ revives : json . data . attributes . gameModeStats [ mode ] . revives ,
134
+ vehicleDestroys : json . data . attributes . gameModeStats [ mode ] . vehicleDestroys
135
+ }
136
+ }
137
+ } )
138
+ return new EmbedBuilder ( )
139
+ . setColor ( '#0099ff' )
140
+ . setTitle ( '전적 정보' )
141
+ . setDescription ( `${ nickName } 님의 ${ mode === null ? "전체" : mode } 전적 정보입니다` )
142
+ . setFields (
143
+ { name : "킬" , value : embedData . kills . toString ( ) , inline : true } ,
144
+ { name : "다운" , value : embedData . DBNOs . toString ( ) , inline : true } ,
145
+ { name : "다운당 킬" , value : ( embedData . kills / embedData . DBNOs ) . toFixed ( 2 ) . toString ( ) , inline : true } ,
146
+ { name : "어시스트" , value : embedData . assists . toString ( ) , inline : true } ,
147
+ { name : "승리" , value : embedData . wins . toString ( ) , inline : true } ,
148
+ { name : "탑10" , value : embedData . top10s . toString ( ) , inline : true } ,
149
+ { name : "라운드 플레이" , value : embedData . roundsPlayed . toString ( ) , inline : true } ,
150
+ { name : "헤드샷 킬" , value : embedData . headshotKills . toString ( ) , inline : true } ,
151
+ { name : "헤드샷 비울" , value : ( embedData . headshotKills / embedData . kills ) . toFixed ( 2 ) . toString ( ) , inline : true } ,
152
+ { name : "데미지" , value : embedData . damageDealt . toFixed ( 2 ) . toString ( ) , inline : true } ,
153
+ { name :"고라니" , value : embedData . roadKills . toString ( ) , inline : true } ,
154
+ { name : "팀킬" , value : embedData . teamKills . toString ( ) , inline : true } ,
155
+ { name : "생존 시간" , value : ( embedData . timeSurvived / 60 ) . toFixed ( 2 ) . toString ( ) , inline : true } ,
156
+ { name : "평균 생존 시간" , value : ( embedData . timeSurvived / embedData . roundsPlayed / 60 ) . toFixed ( 2 ) . toString ( ) , inline : true } ,
157
+ { name : "부스트 아이템 사용" , value : embedData . boosts . toString ( ) , inline : true } ,
158
+ { name : "힐 아이템 사용" , value : embedData . heals . toString ( ) , inline : true } ,
159
+ { name : "무기 획득" , value : embedData . weaponsAcquired . toString ( ) , inline : true } ,
160
+ { name : "팀원 소생" , value : embedData . revives . toString ( ) , inline : true } ,
161
+ { name : "차량 파괴" , value : embedData . vehicleDestroys . toString ( ) , inline : true } ,
162
+ {
163
+ name : "승률" ,
164
+ value : ( ( embedData . wins / embedData . roundsPlayed ) * 100 ) . toFixed ( 2 ) . toString ( ) + "%" ,
165
+ inline : true
166
+ } ,
167
+ { name : "라운드 평균 킬" , value : ( embedData . kills / embedData . roundsPlayed ) . toFixed ( 2 ) . toString ( ) , inline : true } ,
168
+ { name : "라운드 평균 데미지" , value : ( embedData . damageDealt / embedData . roundsPlayed ) . toFixed ( 2 ) . toString ( ) , inline : true } ,
169
+ { name : "라운드 평균 어시스트" , value : ( embedData . assists / embedData . roundsPlayed ) . toFixed ( 2 ) . toString ( ) , inline : true } ,
170
+ { name : "라운드 평균 헤드샷 킬" , value : ( embedData . headshotKills / embedData . roundsPlayed ) . toFixed ( 2 ) . toString ( ) , inline : true } ,
171
+ ) ;
172
+ }
173
+
43
174
44
175
module . exports = {
45
176
data : data ,
@@ -72,38 +203,74 @@ module.exports = {
72
203
73
204
interaction . reply ( { embeds : [ mapEmbed ] } ) ;
74
205
}
75
- if ( interaction . options . getSubcommand ( ) === '전적' ) {
206
+
207
+ //전적
208
+ if ( interaction . options . getSubcommand ( ) === '전적' ) {
76
209
const nickname = interaction . options . getString ( '닉네임' ) ;
77
210
const platform = interaction . options . getString ( '플렛폼' ) ;
211
+ const mode = interaction . options . getString ( '모드' ) ;
78
212
await fetch ( `https://api.pubg.com/shards/${ platform } /players?filter[playerNames]=${ nickname } ` , {
79
213
method : 'GET' ,
80
214
headers : {
81
- "Authorization" : "Bearer " + process . env . PUBG_KEY ,
215
+ "Authorization" : "Bearer " + process . env . PUBG_KEY ,
82
216
"Accept" : "application/vnd.api+json"
83
217
}
84
218
} )
85
219
. then ( json => json . json ( ) )
86
220
. then ( async json => {
87
- console . log ( json ) ;
88
221
// if (json.data.length === 0) {
89
222
// const embed = new EmbedBuilder()
90
223
// .setColor('#0099ff')
91
224
// .setTitle('전적 정보')
92
225
// .setDescription(`${nickname}인 유저를 찾을 수 없습니다`)
93
- // } else if (json.data.length === 1) {
94
- // await fetch(`https://api.pubg.com/shards/${platform}/players/${nickname}`, {
95
- // method: 'GET',
96
- // headers: {
97
- // "Authorization": "Bearer " + process.env.PUBG_KEY,
98
- // "Accept": "application/vnd.api+json"
99
- // }
226
+ // return interaction.reply({embeds: [embed]});
227
+ // } else if (json.data.length > 1) {
228
+ // const selectEmbed = new EmbedBuilder()
229
+ // .setColor('#0099ff')
230
+ // .setTitle('플레이어 선택')
231
+ // .setDescription(`닉네임이 ${nickname}인 플레이어가 ${json.data.length}명입니다. 선택해주세요`);
232
+ //
233
+ // const selectMenu = new StringSelectMenuBuilder()
234
+ // .setCustomId('selectMenu')
235
+ // .setPlaceholder('플레이어 선택')
236
+ // .addOptions(json.data.map(player => new StringSelectMenuOptionBuilder()
237
+ // .setLabel(player.attributes.name)
238
+ // .setValue(player.id)
239
+ // .setDescription(player.attributes.name)
240
+ // .setEmoji('👤')
241
+ // ))
242
+ // const actionRow = new ActionRowBuilder()
243
+ // .addComponents(selectMenu);
244
+ // const response = await interaction.reply({embeds: [selectEmbed], components: [actionRow]});
245
+ //
246
+ // const collector = response.createMessageComponentCollector({
247
+ // componentType: ComponentType.StringSelect,
248
+ // time: 3_600_000
249
+ // });
250
+ //
251
+ // collector.on('collect', async i => {
252
+ // const playerId = i.values[0];
253
+ // const mode = interaction.options.getString('모드');
254
+ // await interaction.editReply({embeds: [await getPlayerData(playerId, mode, 'lifetime')]});
100
255
// })
101
- // .then(json => json.json())
102
- // .then(json => {
103
- // console.log(json);
104
- // })
105
256
// }
257
+ if ( ! json . data ) {
258
+ await interaction . reply (
259
+ {
260
+ embeds :[ new EmbedBuilder ( )
261
+ . setColor ( '#ff0000' )
262
+ . setTitle ( '플레이어를 찾을 수 없습니다' )
263
+ ]
264
+ }
265
+ ) ;
266
+ }
267
+ else if ( json . data . length === 1 ) {
268
+ const playerId = json . data [ 0 ] . id ;
269
+ const embed = await getPlayerData ( nickname , playerId , mode , 'lifetime' )
270
+ await interaction . reply ( { embeds : [ embed ] } ) ;
271
+ }
272
+
106
273
} )
107
274
}
108
275
}
109
- }
276
+ }
0 commit comments