From 5cdf88a64a91ea67a46a5e2dc9f8b159b814c118 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Joona=20Kyt=C3=B6niemi?= <jnkyto@utu.fi>
Date: Thu, 13 Apr 2023 14:49:54 +0300
Subject: [PATCH] Updates

---
 src/Bot.ts                              | 13 +++++----
 src/cmd/Commands.ts                     |  5 +++-
 src/cmd/InsultCommand.ts                |  7 +++--
 src/cmd/MenuCommand.ts                  | 38 +++++++++++++++++++++++--
 src/interfaces/Command.ts               |  4 +--
 src/listeners/InteractionCreate.ts      |  3 +-
 src/models/InternalModel.ts             |  3 +-
 src/utils/{StartupTimer.ts => Timer.ts} |  2 +-
 8 files changed, 58 insertions(+), 17 deletions(-)
 rename src/utils/{StartupTimer.ts => Timer.ts} (92%)

diff --git a/src/Bot.ts b/src/Bot.ts
index 78b05c3..6831aa4 100644
--- a/src/Bot.ts
+++ b/src/Bot.ts
@@ -3,19 +3,22 @@ import dotenv from 'dotenv';
 
 import InteractionCreate from './listeners/InteractionCreate';
 import Ready from './listeners/ReadyListener';
-import {StartupTimer} from './utils/StartupTimer';
+import {Timer} from './utils/Timer';
 
 dotenv.config();
 
-const timer = new StartupTimer(Date.now());
+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;
+
+const startupTimer : Timer = new Timer(Date.now());
 console.log('Ramsay is warming up...');
 
-const token = process.env.DISCORD_TOKEN || 'Missing token, check .env-file.';
-const client = new Client({ intents: [GatewayIntentBits.Guilds] });
+const token : string = process.env.DISCORD_TOKEN || 'Missing token, check .env-file.';
+const client : Client = new Client({ intents: [GatewayIntentBits.Guilds] });
 
 Ready(client);
 InteractionCreate(client);
 
 client.login(token);
 
-console.log(`Ramsay has warmed up, took ${timer.getTookMillis(Date.now())}ms!`);
\ No newline at end of file
+console.log(`Ramsay has warmed up, took ${startupTimer.getTookMillis(Date.now())}ms!`);
\ No newline at end of file
diff --git a/src/cmd/Commands.ts b/src/cmd/Commands.ts
index 164436f..3b234aa 100644
--- a/src/cmd/Commands.ts
+++ b/src/cmd/Commands.ts
@@ -1,4 +1,7 @@
 import {InsultCommand} from './InsultCommand';
+import {MenuCommand} from './MenuCommand';
 import {Command} from '../interfaces/Command';
+import {DEBUG_MODE} from '../Bot';
 
-export const Commands: Command[] = [InsultCommand];
\ No newline at end of file
+const isDebug : boolean = DEBUG_MODE;
+export const Commands : Command[] = [InsultCommand, MenuCommand];
diff --git a/src/cmd/InsultCommand.ts b/src/cmd/InsultCommand.ts
index 8719ff3..a17574a 100644
--- a/src/cmd/InsultCommand.ts
+++ b/src/cmd/InsultCommand.ts
@@ -1,7 +1,7 @@
 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.'
@@ -20,9 +20,10 @@ export const InsultCommand: Command = {
     run: async (client: Client, interaction: CommandInteraction) => {
         const content = insults[getRandomInt(0, insults.length-1)];
 
+
         await interaction.followUp({
             ephemeral: false,
             content
         });
     }
-}; 
\ No newline at end of file
+};
\ No newline at end of file
diff --git a/src/cmd/MenuCommand.ts b/src/cmd/MenuCommand.ts
index 2a95828..06c0fc3 100644
--- a/src/cmd/MenuCommand.ts
+++ b/src/cmd/MenuCommand.ts
@@ -1,17 +1,51 @@
+import axios from 'axios';
 import {Client, CommandInteraction} from 'discord.js';
 
 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)',
     type: 1, // CHAT_INPUT
+    options: [
+        {
+            name: 'today',
+            description: 'What\'s on the menu today?',
+            type: 1,
+        },
+        {
+            name: 'week',
+            description: 'Okay',
+            type: 1
+        }
+    ],
     run: async (client: Client, interaction: CommandInteraction) => {
-        const content = 'No.'; // no functionality yet
+        let messageContent : string   = '';
+        switch (interaction.options.data[0].name) {
+        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)
+                    }
+
+                }
+            );
+            break;
+        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.';
+        }
 
         await interaction.followUp({
             ephemeral: false,
-            content
+            content: messageContent
         });
     }
 };
\ No newline at end of file
diff --git a/src/interfaces/Command.ts b/src/interfaces/Command.ts
index 8584764..5a91569 100644
--- a/src/interfaces/Command.ts
+++ b/src/interfaces/Command.ts
@@ -1,5 +1,5 @@
-import { ChatInputApplicationCommandData, Client, CommandInteraction } from 'discord.js';
+import {ApplicationCommandOptionData, ChatInputApplicationCommandData, Client, CommandInteraction} from 'discord.js';
 
 export interface Command extends ChatInputApplicationCommandData {
-    run: (client: Client, interaction: CommandInteraction) => void;
+    run: (client: Client, interaction: CommandInteraction, options?: ApplicationCommandOptionData) => void;
 }
\ No newline at end of file
diff --git a/src/listeners/InteractionCreate.ts b/src/listeners/InteractionCreate.ts
index 85b6d83..a99868e 100644
--- a/src/listeners/InteractionCreate.ts
+++ b/src/listeners/InteractionCreate.ts
@@ -1,7 +1,6 @@
-import { Client, CommandInteraction, Interaction } from 'discord.js';
+import {Client, CommandInteraction, Interaction} from 'discord.js';
 
 import {Commands} from '../cmd/Commands';
-
 export default (client: Client): void => {
     client.on('interactionCreate', async (interaction: Interaction) => {
         if (interaction.isCommand()) {
diff --git a/src/models/InternalModel.ts b/src/models/InternalModel.ts
index 4250ed6..557ed7a 100644
--- a/src/models/InternalModel.ts
+++ b/src/models/InternalModel.ts
@@ -1,4 +1,5 @@
-import { Locale } from 'discord.js';
+import {Locale} from 'discord.js';
+
 export class EventData {
     constructor(
     public lang: Locale,
diff --git a/src/utils/StartupTimer.ts b/src/utils/Timer.ts
similarity index 92%
rename from src/utils/StartupTimer.ts
rename to src/utils/Timer.ts
index 3ef7c44..927a92a 100644
--- a/src/utils/StartupTimer.ts
+++ b/src/utils/Timer.ts
@@ -1,4 +1,4 @@
-export class StartupTimer {
+export class Timer {
     private readonly start_ms : number;
     private end_ms : number;
     constructor(start_ms : number) {
-- 
GitLab