diff --git a/src/Bot.ts b/src/Bot.ts index 78b05c33b3a92c6568f6d4181aba2733ce58287a..6831aa407ff1b793ac105b5c3c8d992499d82703 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 164436ff502c44a610883dc0fb57b86c6c04ed48..3b234aab17ba7a619799d914fe42ff2f3564a24e 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 8719ff3946088ec6aa614cfcbc3b19ba99e52510..a17574ac44c8ec8ccd67fb6602e10cb961943e2a 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 2a95828af8474b35a15ec278fd107772fbda071b..06c0fc373b07d76752a1884504d77bb0cc220882 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 85847648bdca607d60ea0d83beda436b28bd46b8..5a915691a7a317c53b29fbea77484430384e5f8d 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 85b6d83838dba90cd7c5e9c9d3543ccac4934205..a99868e3ce6b13d2546a9950fb71a6e2f1da9c9c 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 4250ed6315141ecd125126720b530cdcb2e2c1ad..557ed7aa61acf0ca004b083467ce7f6c36088bdb 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 3ef7c4402cf259079a476d3cf822e8d19ba8ef7f..927a92a7eb3833a1ea07388844c99318430b05f5 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) {