From a5ac5cde0e3fd3e5b2ae4c053c2bcd6a8d6c8382 Mon Sep 17 00:00:00 2001 From: KungKurt Date: Sun, 23 Feb 2025 18:28:31 +0100 Subject: [PATCH] updated to version 0.1.18 --- module.json | 2 +- scripts/puckoapi/puckoapi.js | 10 +++++++++- scripts/puckochat/commands.js | 30 ++++++++++++++++++++++++++++++ 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/module.json b/module.json index 72ce91d..e6352cb 100644 --- a/module.json +++ b/module.json @@ -6,7 +6,7 @@ "authors": [ { "name": "Robin Riis" } ], - "version": "0.1.17", + "version": "0.1.18", "socket": true, "minimumCoreVersion": 10, "compatibility": { diff --git a/scripts/puckoapi/puckoapi.js b/scripts/puckoapi/puckoapi.js index 78711e0..2d80551 100644 --- a/scripts/puckoapi/puckoapi.js +++ b/scripts/puckoapi/puckoapi.js @@ -6,7 +6,15 @@ export class PuckoPruttApi { this.schema = this.apiUrl + "/schema/" } + _fetch_json(url) { + const response = await fetch(url); + if (!response.ok) { + return -1; + } + return await response.json(); + } + dagens_lunch(spider) { - return fetch(this.apiUrl + "/dagens_lunch/" + spider + "/", {method: "GET"}); + return this._fetch_json(this.apiUrl + "/dagens_lunch/" + spider + "/?format=json"); } } \ No newline at end of file diff --git a/scripts/puckochat/commands.js b/scripts/puckochat/commands.js index da421a3..fcab14b 100644 --- a/scripts/puckochat/commands.js +++ b/scripts/puckochat/commands.js @@ -2,6 +2,35 @@ function test(user) { return `hello ${user}`; } +function dagens(user, message) { + let week = game.modules.get("puckoprutt-foundry-module").api.dagens_lunch(message[1]); + if (typeof week !== 'object') { + return "could not fetch "+message[1]; + } + let today = new Date().getDay(); + ret = ""; + switch(today) { + case 1: + ret = week["monday"]; + break; + case 2: + ret = week["tuesday"]; + break; + case 3: + ret = week["wednesday"]; + break; + case 4: + ret = week["thursday"]; + break; + case 5: + ret = week["friday"]; + break; + default: + ret = "Ingen dagens under helger." + }; + return ret; +} + export default function puckocommand(user, world, log, message, data) { console.log(`user: ${user}`); console.log(`world: ${world}`); @@ -11,5 +40,6 @@ export default function puckocommand(user, world, log, message, data) { console.log(`data: `); console.log(data); if(message[0] === "test") return test(user.name); + if(message[0] === "dagens") return dagens(user.name) return "" } \ No newline at end of file