update lets to consts

This commit is contained in:
Shay
2022-04-06 16:40:11 -07:00
parent a7f3420435
commit c35e3fb910
8 changed files with 27 additions and 27 deletions

10
app.js
View File

@@ -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] = {

View File

@@ -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({

View File

@@ -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);

View File

@@ -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)

View File

@@ -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 = '';

View File

@@ -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({

View File

@@ -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

View File

@@ -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)];
}