From c35e3fb91028aa73b3f382286e3f2b4b7df68e61 Mon Sep 17 00:00:00 2001 From: Shay Date: Wed, 6 Apr 2022 16:40:11 -0700 Subject: [PATCH] update lets to consts --- app.js | 10 +++++----- commands.js | 8 ++++---- examples/button.js | 6 +++--- examples/command.js | 8 ++++---- examples/modal.js | 6 +++--- examples/selectMenu.js | 8 ++++---- game.js | 6 +++--- utils.js | 2 +- 8 files changed, 27 insertions(+), 27 deletions(-) diff --git a/app.js b/app.js index 91f1826..fcd0a3b 100644 --- a/app.js +++ b/app.js @@ -17,14 +17,14 @@ const client = axios.create({ }); // Store for in-progress games. In production, you'd want to use a DB -let activeGames = {}; +const activeGames = {}; /** * Interactions endpoint URL where Discord will send HTTP requests */ app.post('/interactions', function (req, res) { // Interaction type and data - let { type, id, data } = req.body; + const { type, id, data } = req.body; /** * Handle verification requests @@ -38,7 +38,7 @@ app.post('/interactions', function (req, res) { * See https://discord.com/developers/docs/interactions/application-commands#slash-commands */ if (type === InteractionType.APPLICATION_COMMAND){ - let { name } = data; + const { name } = data; // "test" guild command if (name === "test") { @@ -53,9 +53,9 @@ app.post('/interactions', function (req, res) { } // "challenge" guild command if (name === "challenge" && id) { - let userId = req.body.member.user.id; + const userId = req.body.member.user.id; // User's object choice - let objectName = req.body.data.options[0].value; + const objectName = req.body.data.options[0].value; // Create active game using message ID as the game ID activeGames[id] = { diff --git a/commands.js b/commands.js index c516716..9e8a165 100644 --- a/commands.js +++ b/commands.js @@ -13,9 +13,9 @@ async function HasGuildCommand(client, appId, guildId, command) { const url = DiscordAPI(`applications/${appId}/guilds/${guildId}/commands`); try { - let { data } = await client({ url, method: 'get'}); + const { data } = await client({ url, method: 'get'}); if (data) { - let installedNames = data.map((c) => c["name"]); + const installedNames = data.map((c) => c["name"]); // This is just matching on the name, so it's not good for updates if (!installedNames.includes(command["name"])) { await InstallGuildCommand(client, appId, guildId, command); @@ -38,8 +38,8 @@ export async function InstallGuildCommand(client, appId, guildId, command) { // Get the game choices from game.js function createCommandChoices() { - let choices = getRPSChoices(); - let commandChoices = []; + const choices = getRPSChoices(); + const commandChoices = []; for (let choice of choices) { commandChoices.push({ diff --git a/examples/button.js b/examples/button.js index 2afad39..aebc198 100644 --- a/examples/button.js +++ b/examples/button.js @@ -9,7 +9,7 @@ app.use(express.json({verify: VerifyDiscordRequest(process.env.PUBLIC_KEY)})); app.post('/interactions', function (req, res) { // Interaction type and data - let { type, data } = req.body; + const { type, data } = req.body; /** * Handle slash command requests */ @@ -42,9 +42,9 @@ app.post('/interactions', function (req, res) { */ if (type === InteractionType.MESSAGE_COMPONENT){ // custom_id set in payload when sending message component - let componentId = data.custom_id; + const componentId = data.custom_id; // user who clicked button - let userId = req.body.member.user.id; + const userId = req.body.member.user.id; if (componentId === 'my_button') { console.log(req.body); diff --git a/examples/command.js b/examples/command.js index e3de94d..cff0e07 100644 --- a/examples/command.js +++ b/examples/command.js @@ -10,7 +10,7 @@ app.use(express.json({verify: VerifyDiscordRequest(process.env.PUBLIC_KEY)})); app.post('/interactions', function (req, res) { // Interaction type and data - let { type, data } = req.body; + const { type, data } = req.body; /** * Handle slash command requests */ @@ -27,8 +27,8 @@ app.post('/interactions', function (req, res) { }); function createCommand() { - let appId = process.env.APP_ID; - let guildId = process.env.GUILD_ID; + const appId = process.env.APP_ID; + const guildId = process.env.GUILD_ID; /** * Globally-scoped slash commands (generally only recommended for production) @@ -41,7 +41,7 @@ function createCommand() { * See https://discord.com/developers/docs/interactions/application-commands#create-guild-application-command */ const guildUrl = DiscordAPI(`applications/${appId}/guilds/${guildId}/commands`); - let commandBody = { + const commandBody = { "name": "test", "description": "Just your average command", // chat command (see https://discord.com/developers/docs/interactions/application-commands#application-command-object-application-command-types) diff --git a/examples/modal.js b/examples/modal.js index af651e9..e4d9dc0 100644 --- a/examples/modal.js +++ b/examples/modal.js @@ -10,7 +10,7 @@ app.use(express.json({verify: VerifyDiscordRequest(process.env.PUBLIC_KEY)})); app.post('/interactions', function (req, res) { // Interaction type and data - let { type, data } = req.body; + const { type, data } = req.body; /** * Handle slash command requests */ @@ -60,9 +60,9 @@ app.post('/interactions', function (req, res) { */ if (type === InteractionType.APPLICATION_MODAL_SUBMIT) { // custom_id of modal - let modalId = data.custom_id; + const modalId = data.custom_id; // user ID of member who filled out modal - let userId = req.body.member.user.id; + const userId = req.body.member.user.id; if (modalId === 'my_modal') { let modalValues = ''; diff --git a/examples/selectMenu.js b/examples/selectMenu.js index dcf5f4f..c4e3fb1 100644 --- a/examples/selectMenu.js +++ b/examples/selectMenu.js @@ -9,7 +9,7 @@ app.use(express.json({verify: VerifyDiscordRequest(process.env.PUBLIC_KEY)})); app.post('/interactions', function (req, res) { // Interaction type and data - let { type, data } = req.body; + const { type, data } = req.body; /** * Handle slash command requests */ @@ -53,14 +53,14 @@ app.post('/interactions', function (req, res) { */ if (type === InteractionType.MESSAGE_COMPONENT){ // custom_id set in payload when sending message component - let componentId = data.custom_id; + const componentId = data.custom_id; if (componentId === 'my_select') { console.log(req.body); // Get selected option from payload - let selectedOption = data.values[0]; - let userId = req.body.member.user.id; + const selectedOption = data.values[0]; + const userId = req.body.member.user.id; // Send results return res.send({ diff --git a/game.js b/game.js index c7dae1c..b0327d9 100644 --- a/game.js +++ b/game.js @@ -17,7 +17,7 @@ export function getResult(p1, p2) { } function formatResult(result) { - let { win, lose, verb } = result; + const { win, lose, verb } = result; return verb === 'tie' ? `<@${win.id}> and <@${lose.id}> draw with **${win.objectName}**` : `<@${win.id}>'s **${win.objectName}** ${verb} <@${lose.id}>'s **${lose.objectName}**`; @@ -75,8 +75,8 @@ export function getRPSChoices() { // Function to fetch shuffled options for select menu export function getShuffledOptions() { - let allChoices = getRPSChoices(); - let options = []; + const allChoices = getRPSChoices(); + const options = []; for (let c of allChoices) { // Formatted for select menus diff --git a/utils.js b/utils.js index 399d102..3f99372 100644 --- a/utils.js +++ b/utils.js @@ -16,7 +16,7 @@ export function DiscordAPI(url) { return 'https://discord.com/api/v9/' + url }; // Simple method that returns a random emoji from list export function getRandomEmoji() { - let emojiList = ['😭', 'πŸ˜„', '😌', 'πŸ€“', '😎', '😀', 'πŸ€–', 'πŸ˜Άβ€πŸŒ«οΈ', '🌏', 'πŸ“Έ', 'πŸ’Ώ', 'πŸ‘‹', '🌊', '✨']; + const emojiList = ['😭', 'πŸ˜„', '😌', 'πŸ€“', '😎', '😀', 'πŸ€–', 'πŸ˜Άβ€πŸŒ«οΈ', '🌏', 'πŸ“Έ', 'πŸ’Ώ', 'πŸ‘‹', '🌊', '✨']; return emojiList[Math.floor(Math.random() * emojiList.length)]; }