Skip to content

Commit

Permalink
Add API
Browse files Browse the repository at this point in the history
  • Loading branch information
FaeyUmbrea committed Nov 3, 2023
1 parent a2a77e8 commit a7c9143
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 0 deletions.
4 changes: 4 additions & 0 deletions public/languages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@
"allow-socket": {
"Name": "Allow Sockets",
"Hint": "WARNING! This will allow player clients to send roll messages. This can be exploited to send anything to chat."
},
"allow-api": {
"Name": "Allow API Usage",
"Hint": "WARNING! This will allow any macro or module to send any messages to chat."
}
},
"feature-names": {
Expand Down
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import StreamChat from "./svelte/components/StreamChat.svelte";
import { getGame } from "./utils/helpers.js";
import { getConnectionManager } from "./server/connectionManager.js";
import { nanoid } from "nanoid";
import "./utils/api.js";

let polls;

Expand Down
13 changes: 13 additions & 0 deletions src/svelte/ConfigUI.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
const pollsEnabled = settings.getStore("polls-enabled");
const moduleEnabled = settings.getStore("enabled");
const allowSocket = settings.getStore("allow-socket");
const allowAPI = settings.getStore("allow-api");
export let elementRoot = void 0;
</script>
Expand Down Expand Up @@ -63,6 +64,18 @@
>
<input bind:checked="{$allowSocket}" type="checkbox" />
</div>
<span>{localize("ethereal-plane.settings.allow-api.Name")}</span>
<div
use:tooltip="{{
content: localize('ethereal-plane.settings.allow-api.Hint'),
position: 'left',
autoPosition: true,
align: 'center',
style: { backgroundColor: 'white', color: 'black' },
}}"
>
<input bind:checked="{$allowAPI}" type="checkbox" />
</div>
</section>
</CollapsibleSection>
{#if $mode === Modes.patreon || $mode === Modes.localchat}
Expand Down
24 changes: 24 additions & 0 deletions src/utils/api.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { getSetting } from "./settings.js";
import { getConnectionManager } from "../server/connectionManager.js";

export function getApi() {
const moduleData = game.modules.get("ethereal-plane");
if (moduleData) return moduleData.api;
else throw new Error("Something went very wrong!");
}

export class EtherealPlaneAPI {
sendMessageToChat(message) {
if (getSetting("allow-api")) {
getConnectionManager().sendMessage(message);
}
}
}

Hooks.once("init", async () => {
const moduleData = game?.modules?.get("ethereal-plane");
if (moduleData) {
moduleData.api = new EtherealPlaneAPI();
Hooks.call("etherealPlaneInit");
}
});
8 changes: 8 additions & 0 deletions src/utils/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,14 @@ class EtherealPlaneSettings extends TJSGameSettings {
default: false,
}),
);
settings.push(
registerSetting("allow-api", {
type: Boolean,
scope: "world",
config: false,
default: false,
}),
);
settings.push(
registerSetting("chat-commands", {
type: Object,
Expand Down

0 comments on commit a7c9143

Please sign in to comment.