Skip to content

Commit

Permalink
chat command
Browse files Browse the repository at this point in the history
  • Loading branch information
Forien committed Feb 18, 2025
1 parent 93e6d69 commit d81a631
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# Changelog

## v0.1.1 - 18-02-2025
* Added `/effect X` chat command

## v0.1.0 - 18-02-2025
* Initial release
22 changes: 22 additions & 0 deletions dist/champions-now.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2250,3 +2250,25 @@ Hooks.once("ready", () => {
Hooks.once("renderChatLog", (app, html, _options) => {
html.addClass("champions-now");
});

Hooks.on("chatMessage", (html, content, msg) => {
const rollMode = game.settings.get("core", "rollMode");

if (["gmroll", "blindroll"].includes(rollMode))
msg["whisper"] = ChatMessage.getWhisperRecipients("GM").map(u => u.id);

if (rollMode === "blindroll")
msg["blind"] = true;

const regExp = /(\S+)/g;
const commands = content.match(regExp);
const command = commands[0];

if (command === "/effect") {
const amount = Number(commands[1]) ?? 3;
const roll = new EffectRoll(`${amount}d6`);
roll.toMessage();

return false;
}
});
23 changes: 23 additions & 0 deletions src/champions-now.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {registerHandlebarsHelpers} from "./modules/handlebars.mjs";
import {initialConfig, registerDataModels, registerSheets, setDocumentClasses} from "./modules/config.mjs";
import {registerSettings} from "./modules/Settings.mjs";
import Utility from "./modules/utility/Utility.mjs";
import EffectRoll from "./modules/features/EffectRoll.mjs";

Hooks.once("init", () => {
game.system.links = LINKS;
Expand Down Expand Up @@ -45,4 +46,26 @@ Hooks.once("ready", () => {

Hooks.once("renderChatLog", (app, html, _options) => {
html.addClass("champions-now");
});

Hooks.on("chatMessage", (html, content, msg) => {
const rollMode = game.settings.get("core", "rollMode");

if (["gmroll", "blindroll"].includes(rollMode))
msg["whisper"] = ChatMessage.getWhisperRecipients("GM").map(u => u.id);

if (rollMode === "blindroll")
msg["blind"] = true;

const regExp = /(\S+)/g;
const commands = content.match(regExp);
const command = commands[0];

if (command === "/effect") {
const amount = Number(commands[1]) ?? 3;
const roll = new EffectRoll(`${amount}d6`);
roll.toMessage();

return false;
}
});

0 comments on commit d81a631

Please sign in to comment.