diff --git a/.eslintrc.json b/.eslintrc.json index 6cbc0c6ee758f1adbd2f0c9a60262a8c9ffd6a04..20d7aac01fac28486a1c8f89372df3152c92087b 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 193c39786191ea834b612a368f9cf402f7584a58..b65d5655fd5e48bc270f3e6f44e570f009b42b0a 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 6831aa407ff1b793ac105b5c3c8d992499d82703..51e31fdc43d6611be2cf81fc5f5cfedf94dfb3da 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 3b234aab17ba7a619799d914fe42ff2f3564a24e..eaf02f04d870d4960db36f1017bcb27ec18b66e2 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 a17574ac44c8ec8ccd67fb6602e10cb961943e2a..46963b446160c454bbe123847497702bbbb2464d 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 06c0fc373b07d76752a1884504d77bb0cc220882..2da77450a4243a2995d8718d9bdcc2155a8e982d 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 5a915691a7a317c53b29fbea77484430384e5f8d..c9d2612c7c70fa94e059f898a7ce8326d03d9bde 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 a99868e3ce6b13d2546a9950fb71a6e2f1da9c9c..72ea86ad406c58a23507cb1dff7a2ceef65ad966 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 cf0687d008689e02059f8093fcf3df76f76ecaf8..810621025cd464232a2937558737abb3f39aee0d 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 557ed7aa61acf0ca004b083467ce7f6c36088bdb..4e79d5d53fdb75f2f45f1b780258d1e590a1f793 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(