Use !halostats [gamertag] to show off your stats! Includes error checking for people who don't exist/haven't played before
// authenticates you with the API standard library
// type `await lib.` to display API autocomplete
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
let gamertag = context.params.event.content.replace('!halostats ', '');
let haloData;
try {
haloData = await lib.halo.infinite['@0.2.3'].stats['service-record']({
gamertag: gamertag,
experience: 'pvp-only',
});
} catch (e) {
return await lib.discord.channels['@0.2.0'].messages.create({
channel_id: `${context.params.event.channel_id}`,
content: '',
tts: false,
embeds: [
{
type: 'rich',
title: `β Oh no!`,
description: `Hey, dont be silly now. Come on, I can't search a non-existing account. Try again!`,
color: 0xff0000,
},
],
});
}
// If user hasn't played Halo Infinite yet, return an error
if (haloData.data.matches_played === 0) {
return await lib.discord.channels['@0.2.0'].messages.create({
channel_id: `${context.params.event.channel_id}`,
content: '',
tts: false,
embeds: [
{
type: 'rich',
title: `β Oh no!`,
description: `That person doesn't seem to have played Halo Infinite yet (WAIT WHAT???). Go bug them to play it!`,
color: 0xff0000,
},
],
});
}
return await lib.discord.channels['@0.2.0'].messages.create({
channel_id: `${context.params.event.channel_id}`,
content: '',
tts: false,
embeds: [
{
type: 'rich',
title: `πΆ ${haloData.additional.gamertag}'s Halo Infinite Stats`,
description: '',
color: 0x7300ff,
fields: [
{
name: `β Kills`,
value: haloData.data.core.summary.kills,
inline: true,
},
{
name: `β οΈ Deaths`,
value: haloData.data.core.summary.deaths,
inline: true,
},
{
name: `π€ Assists`,
value: haloData.data.core.summary.assists,
inline: true,
},
{
name: `π€¬ Betrayals`,
value: haloData.data.core.summary.assists,
inline: true,
},
{
name: `π₯ Suicides`,
value: haloData.data.core.summary.suicides,
inline: true,
},
{
name: `π Destroys`,
value: haloData.data.core.summary.vehicles.destroys,
inline: true,
},
{
name: `π Hijacks`,
value: haloData.data.core.summary.vehicles.hijacks,
inline: true,
},
{
name: `π
Medals`,
value: haloData.data.core.summary.medals,
inline: true,
},
],
},
],
});