Skip to content
Snippets Groups Projects
Commit abcbc9d9 authored by Joona Kytöniemi's avatar Joona Kytöniemi :sunglasses:
Browse files

Change eslint quotes to double, begin building api object traversal

parent 5cdf88a6
No related branches found
No related tags found
No related merge requests found
Pipeline #62903 passed
...@@ -85,7 +85,7 @@ ...@@ -85,7 +85,7 @@
"prefer-const": "off", "prefer-const": "off",
"quotes": [ "quotes": [
"error", "error",
"single", "double",
{ {
"allowTemplateLiterals": true "allowTemplateLiterals": true
} }
......
...@@ -18,7 +18,7 @@ jolloin projektin vaatima Node-versio asennetaan ja otetaan käyttöön automaat ...@@ -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 `npm install`, joka lataa projektin tarvitsemat kirjastot. Luo projektin juureen `.env`-niminen tiedosto, jonka
sisältö on seuraavanlainen: sisältö on seuraavanlainen:
```dotenv ```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`. Tämän jälkeen voit käynnistää botin suorittamalla komennon `npm run start`.
...@@ -32,8 +32,8 @@ komennot `npm run lint` ja tarpeen mukaan `npm run lint:fix` tyylin ylläpitämi ...@@ -32,8 +32,8 @@ komennot `npm run lint` ja tarpeen mukaan `npm run lint:fix` tyylin ylläpitämi
### Työkalu/versiolistaus: ### Työkalu/versiolistaus:
| Työkalu | Versio | | Työkalu | Versio |
|---------|--------| |---------|---------|
| Node | 19.8.1 | | Node | 18.15.0 |
| npm | 9.6.4 | | npm | 9.6.4 |
| nvm | 0.39.3 | | nvm | 0.39.3 |
......
import {Client, GatewayIntentBits} from 'discord.js'; import {Client, GatewayIntentBits} from "discord.js";
import dotenv from 'dotenv'; import dotenv from "dotenv";
import InteractionCreate from './listeners/InteractionCreate'; import InteractionCreate from "./listeners/InteractionCreate";
import Ready from './listeners/ReadyListener'; import Ready from "./listeners/ReadyListener";
import {Timer} from './utils/Timer'; import {Timer} from "./utils/Timer";
dotenv.config(); dotenv.config();
export const DEBUG_MODE : boolean = true; // TODO: define this in future config json 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; DEBUG_MODE ? console.log("Ramsay is running in debug mode! (this currently has no effect)") : null;
const startupTimer : Timer = new Timer(Date.now()); 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] }); const client : Client = new Client({ intents: [GatewayIntentBits.Guilds] });
Ready(client); Ready(client);
......
import {InsultCommand} from './InsultCommand'; import {InsultCommand} from "./InsultCommand";
import {MenuCommand} from './MenuCommand'; import {MenuCommand} from "./MenuCommand";
import {Command} from '../interfaces/Command'; import {Command} from "../interfaces/Command";
import {DEBUG_MODE} from '../Bot';
const isDebug : boolean = DEBUG_MODE;
export const Commands : Command[] = [InsultCommand, MenuCommand]; export const Commands : Command[] = [InsultCommand, MenuCommand];
import {Client, CommandInteraction} from 'discord.js'; import {Client, CommandInteraction} from "discord.js";
import {Command} from '../interfaces/Command'; import {Command} from "../interfaces/Command";
import {getRandomInt} from '../utils/getRandomInt'; import {getRandomInt} from "../utils/getRandomInt";
let insults = [ 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 { try {
insults = require('../../data/insults.json'); insults = require("../../data/insults.json");
} catch (e) { } 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 = { export const InsultCommand: Command = {
name: 'insult', name: "insult",
description: 'Returns a classic insult uttered by Mr. Gordon Ramsay himself.', description: "Returns a classic insult uttered by Mr. Gordon Ramsay himself.",
type: 1, // CHAT_INPUT type: 1, // CHAT_INPUT
run: async (client: Client, interaction: CommandInteraction) => { run: async (client: Client, interaction: CommandInteraction) => {
const content = insults[getRandomInt(0, insults.length-1)]; const content = insults[getRandomInt(0, insults.length-1)];
......
import axios from 'axios'; import axios from "axios";
import {Client, CommandInteraction} from 'discord.js'; import {Client, CommandInteraction} from "discord.js";
import {Command} from '../interfaces/Command'; import {Command} from "../interfaces/Command";
export const MenuCommand: Command = { export const MenuCommand: Command = {
name: 'menu', name: "menu",
description: 'Fetches the menu of any restaurant that you desire (as long it\'s a student restaurant in Turku)', description: "Fetches the menu of any restaurant that you desire (as long it's a student restaurant in Turku)",
type: 1, // CHAT_INPUT type: 1, // CHAT_INPUT
options: [ options: [
{ {
name: 'today', name: "today",
description: 'What\'s on the menu today?', description: "What's on the menu today?",
type: 1, type: 1,
}, },
{ {
name: 'week', name: "week",
description: 'Okay', description: "Okay",
type: 1 type: 1
} }
], ],
run: async (client: Client, interaction: CommandInteraction) => { run: async (client: Client, interaction: CommandInteraction) => {
let messageContent : string = ''; let messageContent = "";
let apiJson;
switch (interaction.options.data[0].name) { switch (interaction.options.data[0].name) {
case 'today': case "today":
axios.get('http://127.0.0.1:5000/restaurants/').then( axios.get("http://127.0.0.1:5000/restaurants/").then(
r => { r => {
console.log(r.data); apiJson = r.data;
for (const val in r.data) { Object.entries(apiJson).forEach(([key, entries]) => {
console.log(val) 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; break;
case 'week': case "week":
messageContent += 'I wouldn\'t know, I just work here.'; messageContent += "I wouldn't know, I just work here.";
break; break;
} }
if (messageContent === '') { if (messageContent === "") {
messageContent += 'I tried to get the data but I couldn\'t. Not my fault bro.'; messageContent += "I tried to get the data but I couldn't. Not my fault bro.";
} }
await interaction.followUp({ await interaction.followUp({
......
import {ApplicationCommandOptionData, ChatInputApplicationCommandData, Client, CommandInteraction} from 'discord.js'; import {ApplicationCommandOptionData, ChatInputApplicationCommandData, Client, CommandInteraction} from "discord.js";
export interface Command extends ChatInputApplicationCommandData { export interface Command extends ChatInputApplicationCommandData {
run: (client: Client, interaction: CommandInteraction, options?: ApplicationCommandOptionData) => void; run: (client: Client, interaction: CommandInteraction, options?: ApplicationCommandOptionData) => void;
......
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 => { export default (client: Client): void => {
client.on('interactionCreate', async (interaction: Interaction) => { client.on("interactionCreate", async (interaction: Interaction) => {
if (interaction.isCommand()) { if (interaction.isCommand()) {
await handleSlashCommand(client, interaction); await handleSlashCommand(client, interaction);
} }
...@@ -12,7 +12,7 @@ export default (client: Client): void => { ...@@ -12,7 +12,7 @@ export default (client: Client): void => {
const handleSlashCommand = async (client: Client, interaction: CommandInteraction): Promise<void> => { const handleSlashCommand = async (client: Client, interaction: CommandInteraction): Promise<void> => {
const slashCommand = Commands.find(cmd => cmd.name === interaction.commandName); const slashCommand = Commands.find(cmd => cmd.name === interaction.commandName);
if (!slashCommand) { if (!slashCommand) {
await interaction.followUp({content: 'An oopsie woopsie has occurred!'}); await interaction.followUp({content: "An oopsie woopsie has occurred!"});
return; return;
} }
await interaction.deferReply(); await interaction.deferReply();
......
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 => { export default (client: Client): void => {
client.on('ready', async () => { client.on("ready", async () => {
if (!client.user || !client.application) { if (!client.user || !client.application) {
return; return;
} }
......
import {Locale} from 'discord.js'; import {Locale} from "discord.js";
export class EventData { export class EventData {
constructor( constructor(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment