From abcbc9d965453cb7051fd9a50dc82eaf8de16317 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joona=20Kyt=C3=B6niemi?= <jnkyto@utu.fi> Date: Tue, 18 Apr 2023 15:03:08 +0300 Subject: [PATCH] Change eslint quotes to double, begin building api object traversal --- .eslintrc.json | 2 +- README.md | 12 +++---- src/Bot.ts | 18 +++++------ src/cmd/Commands.ts | 8 ++--- src/cmd/InsultCommand.ts | 16 +++++----- src/cmd/MenuCommand.ts | 50 +++++++++++++++++------------- src/interfaces/Command.ts | 2 +- src/listeners/InteractionCreate.ts | 8 ++--- src/listeners/ReadyListener.ts | 6 ++-- src/models/InternalModel.ts | 2 +- 10 files changed, 65 insertions(+), 59 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 6cbc0c6..20d7aac 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -85,7 +85,7 @@ "prefer-const": "off", "quotes": [ "error", - "single", + "double", { "allowTemplateLiterals": true } diff --git a/README.md b/README.md index 193c397..b65d565 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ jolloin projektin vaatima Node-versio asennetaan ja otetaan käyttöön automaat `npm install`, joka lataa projektin tarvitsemat kirjastot. Luo projektin juureen `.env`-niminen tiedosto, jonka sisältö on seuraavanlainen: ```dotenv -DISCORD-TOKEN=DISCORDIN_DEVPORTALIIN_LUOMASI_SOVELLUKSEN_BOTIN_TOKEN_TÄHÄN +DISCORD_TOKEN=DISCORDIN_DEVPORTALIIN_LUOMASI_SOVELLUKSEN_BOTIN_TOKEN_TÄHÄN ``` Tämän jälkeen voit käynnistää botin suorittamalla komennon `npm run start`. @@ -31,11 +31,11 @@ komennot `npm run lint` ja tarpeen mukaan `npm run lint:fix` tyylin ylläpitämi ⚠️ JA ÄLKÄÄ VAAN FORCE PUSHATKO!!! ⚠️ ### Työkalu/versiolistaus: -| Työkalu | Versio | -|---------|--------| -| Node | 19.8.1 | -| npm | 9.6.4 | -| nvm | 0.39.3 | +| Työkalu | Versio | +|---------|---------| +| Node | 18.15.0 | +| npm | 9.6.4 | +| nvm | 0.39.3 | ### Tekijät: Joona Kytöniemi diff --git a/src/Bot.ts b/src/Bot.ts index 6831aa4..51e31fd 100644 --- a/src/Bot.ts +++ b/src/Bot.ts @@ -1,19 +1,19 @@ -import {Client, GatewayIntentBits} from 'discord.js'; -import dotenv from 'dotenv'; +import {Client, GatewayIntentBits} from "discord.js"; +import dotenv from "dotenv"; -import InteractionCreate from './listeners/InteractionCreate'; -import Ready from './listeners/ReadyListener'; -import {Timer} from './utils/Timer'; +import InteractionCreate from "./listeners/InteractionCreate"; +import Ready from "./listeners/ReadyListener"; +import {Timer} from "./utils/Timer"; dotenv.config(); -export const DEBUG_MODE : boolean = true; // TODO: define this in future config json -DEBUG_MODE ? console.log('Ramsay is running in debug mode! (this currently has no effect)') : null; +export const DEBUG_MODE = true; // TODO: define this in future config json +DEBUG_MODE ? console.log("Ramsay is running in debug mode! (this currently has no effect)") : null; const startupTimer : Timer = new Timer(Date.now()); -console.log('Ramsay is warming up...'); +console.log("Ramsay is warming up..."); -const token : string = process.env.DISCORD_TOKEN || 'Missing token, check .env-file.'; +const token : string = process.env.DISCORD_TOKEN || "Missing token, check .env-file."; const client : Client = new Client({ intents: [GatewayIntentBits.Guilds] }); Ready(client); diff --git a/src/cmd/Commands.ts b/src/cmd/Commands.ts index 3b234aa..eaf02f0 100644 --- a/src/cmd/Commands.ts +++ b/src/cmd/Commands.ts @@ -1,7 +1,5 @@ -import {InsultCommand} from './InsultCommand'; -import {MenuCommand} from './MenuCommand'; -import {Command} from '../interfaces/Command'; -import {DEBUG_MODE} from '../Bot'; +import {InsultCommand} from "./InsultCommand"; +import {MenuCommand} from "./MenuCommand"; +import {Command} from "../interfaces/Command"; -const isDebug : boolean = DEBUG_MODE; export const Commands : Command[] = [InsultCommand, MenuCommand]; diff --git a/src/cmd/InsultCommand.ts b/src/cmd/InsultCommand.ts index a17574a..46963b4 100644 --- a/src/cmd/InsultCommand.ts +++ b/src/cmd/InsultCommand.ts @@ -1,21 +1,21 @@ -import {Client, CommandInteraction} from 'discord.js'; +import {Client, CommandInteraction} from "discord.js"; -import {Command} from '../interfaces/Command'; -import {getRandomInt} from '../utils/getRandomInt'; +import {Command} from "../interfaces/Command"; +import {getRandomInt} from "../utils/getRandomInt"; let insults = [ - 'The insults.json file was not found. Check if it exists in the /data/-folder in project root. Dumbass.' + "The insults.json file was not found. Check if it exists in the /data/-folder in project root. Dumbass." ]; try { - insults = require('../../data/insults.json'); + insults = require("../../data/insults.json"); } catch (e) { - console.log('An error occurred while trying to load the insults.json -file.'); + console.log("An error occurred while trying to load the insults.json -file."); } export const InsultCommand: Command = { - name: 'insult', - description: 'Returns a classic insult uttered by Mr. Gordon Ramsay himself.', + name: "insult", + description: "Returns a classic insult uttered by Mr. Gordon Ramsay himself.", type: 1, // CHAT_INPUT run: async (client: Client, interaction: CommandInteraction) => { const content = insults[getRandomInt(0, insults.length-1)]; diff --git a/src/cmd/MenuCommand.ts b/src/cmd/MenuCommand.ts index 06c0fc3..2da7745 100644 --- a/src/cmd/MenuCommand.ts +++ b/src/cmd/MenuCommand.ts @@ -1,46 +1,54 @@ -import axios from 'axios'; -import {Client, CommandInteraction} from 'discord.js'; +import axios from "axios"; +import {Client, CommandInteraction} from "discord.js"; -import {Command} from '../interfaces/Command'; +import {Command} from "../interfaces/Command"; export const MenuCommand: Command = { - name: 'menu', - description: 'Fetches the menu of any restaurant that you desire (as long it\'s a student restaurant in Turku)', + name: "menu", + description: "Fetches the menu of any restaurant that you desire (as long it's a student restaurant in Turku)", type: 1, // CHAT_INPUT options: [ { - name: 'today', - description: 'What\'s on the menu today?', + name: "today", + description: "What's on the menu today?", type: 1, }, { - name: 'week', - description: 'Okay', + name: "week", + description: "Okay", type: 1 } ], run: async (client: Client, interaction: CommandInteraction) => { - let messageContent : string = ''; + let messageContent = ""; + let apiJson; switch (interaction.options.data[0].name) { - case 'today': - axios.get('http://127.0.0.1:5000/restaurants/').then( + case "today": + axios.get("http://127.0.0.1:5000/restaurants/").then( r => { - console.log(r.data); - for (const val in r.data) { - console.log(val) - } - + apiJson = r.data; + Object.entries(apiJson).forEach(([key, entries]) => { + if (key !== "updated") { + console.log("Printing info for restaurant ID " + key + "..."); + Object.entries(Object(entries)).forEach(([key, value]) => { + console.log(key + ": " + String(value)); + }); + console.log("\n ------------------------ \n"); + } else { + console.log(key + ": " + String(entries)); + } + }); } ); break; - case 'week': - messageContent += 'I wouldn\'t know, I just work here.'; + case "week": + messageContent += "I wouldn't know, I just work here."; break; } - if (messageContent === '') { - messageContent += 'I tried to get the data but I couldn\'t. Not my fault bro.'; + if (messageContent === "") { + messageContent += "I tried to get the data but I couldn't. Not my fault bro."; } await interaction.followUp({ diff --git a/src/interfaces/Command.ts b/src/interfaces/Command.ts index 5a91569..c9d2612 100644 --- a/src/interfaces/Command.ts +++ b/src/interfaces/Command.ts @@ -1,4 +1,4 @@ -import {ApplicationCommandOptionData, ChatInputApplicationCommandData, Client, CommandInteraction} from 'discord.js'; +import {ApplicationCommandOptionData, ChatInputApplicationCommandData, Client, CommandInteraction} from "discord.js"; export interface Command extends ChatInputApplicationCommandData { run: (client: Client, interaction: CommandInteraction, options?: ApplicationCommandOptionData) => void; diff --git a/src/listeners/InteractionCreate.ts b/src/listeners/InteractionCreate.ts index a99868e..72ea86a 100644 --- a/src/listeners/InteractionCreate.ts +++ b/src/listeners/InteractionCreate.ts @@ -1,8 +1,8 @@ -import {Client, CommandInteraction, Interaction} from 'discord.js'; +import {Client, CommandInteraction, Interaction} from "discord.js"; -import {Commands} from '../cmd/Commands'; +import {Commands} from "../cmd/Commands"; export default (client: Client): void => { - client.on('interactionCreate', async (interaction: Interaction) => { + client.on("interactionCreate", async (interaction: Interaction) => { if (interaction.isCommand()) { await handleSlashCommand(client, interaction); } @@ -12,7 +12,7 @@ export default (client: Client): void => { const handleSlashCommand = async (client: Client, interaction: CommandInteraction): Promise<void> => { const slashCommand = Commands.find(cmd => cmd.name === interaction.commandName); if (!slashCommand) { - await interaction.followUp({content: 'An oopsie woopsie has occurred!'}); + await interaction.followUp({content: "An oopsie woopsie has occurred!"}); return; } await interaction.deferReply(); diff --git a/src/listeners/ReadyListener.ts b/src/listeners/ReadyListener.ts index cf0687d..8106210 100644 --- a/src/listeners/ReadyListener.ts +++ b/src/listeners/ReadyListener.ts @@ -1,9 +1,9 @@ -import {Client} from 'discord.js'; +import {Client} from "discord.js"; -import {Commands} from '../cmd/Commands'; +import {Commands} from "../cmd/Commands"; export default (client: Client): void => { - client.on('ready', async () => { + client.on("ready", async () => { if (!client.user || !client.application) { return; } diff --git a/src/models/InternalModel.ts b/src/models/InternalModel.ts index 557ed7a..4e79d5d 100644 --- a/src/models/InternalModel.ts +++ b/src/models/InternalModel.ts @@ -1,4 +1,4 @@ -import {Locale} from 'discord.js'; +import {Locale} from "discord.js"; export class EventData { constructor( -- GitLab