Skip to content

Commit

Permalink
Merge pull request #10 from elespike/master
Browse files Browse the repository at this point in the history
Add per-tab webhooks
  • Loading branch information
mclemente authored Dec 19, 2023
2 parents 4378488 + 87fd5f8 commit 48dc04a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
8 changes: 5 additions & 3 deletions chat-tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ import { TurndownService } from "./module/TurndownService.js";
import { ChatTabSource, RW_PERMISSIONS, registerSettings, renderSettingsConfigHandler } from "./module/settings.js";

class ChatTab {
constructor({ id, name, permissions = {}, sources = [] }) {
constructor({ id, name, webhook, permissions = {}, sources = [] }) {
this.id = id;
this.name = name;
this.webhook = webhook;
this.sources = game.chatTabs.sources.filter((source) => sources.includes(source.key));
const roles = this.createRolePermissions(permissions.roles);
const users = this.createUserPermissions(permissions.users);
Expand Down Expand Up @@ -294,6 +295,7 @@ class TabbedChatlog {
// Handle Webhooks
try {
const WEBHOOKS = {
tab: game.chatTabs.currentTab.webhook,
scene: game.scenes.get(chatMessage.speaker.scene)?.getFlag("chat-tabs", "webhook") ?? "",
backupIC: game.settings.get("chat-tabs", "icBackupWebhook"),
OOC: game.settings.get("chat-tabs", "oocWebhook"),
Expand All @@ -306,7 +308,7 @@ class TabbedChatlog {
chatMessage.type == CONST.CHAT_MESSAGE_TYPES.EMOTE ||
(sendRoll && chatMessage.speaker.actor)
) {
webhook = WEBHOOKS.scene || WEBHOOKS.backupIC;
webhook = WEBHOOKS.tab || WEBHOOKS.scene || WEBHOOKS.backupIC;
if (!webhook) return;

const speaker = chatMessage.speaker;
Expand All @@ -316,7 +318,7 @@ class TabbedChatlog {
chatMessage.type == CONST.CHAT_MESSAGE_TYPES.OOC ||
(sendRoll && !chatMessage.speaker.actor)
) {
webhook = WEBHOOKS.OOC;
webhook = WEBHOOKS.tab || WEBHOOKS.OOC;
if (!webhook) return;

img = chatMessage.user.avatar;
Expand Down
3 changes: 2 additions & 1 deletion module/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ class TabbedChatTabSettings extends FormApplication {
const data = expandObject(original);
const tabs = [];
for (const key in data.tabs) {
let { id, name, sources, permissions } = data.tabs[key];
let { id, name, webhook, sources, permissions } = data.tabs[key];
permissions.roles = Object.assign(
...Object.keys(permissions.roles).map((key) => ({
[key]: Number(permissions.roles[key]),
Expand All @@ -461,6 +461,7 @@ class TabbedChatTabSettings extends FormApplication {
tabs.push({
id,
name,
webhook,
sources: game.chatTabs.sources.filter((source, index) => sources[index]).map((source) => source.key),
permissions,
});
Expand Down
2 changes: 2 additions & 0 deletions templates/ChatTabs.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
<div class="form-group">
<label>{{localize "Name"}}</label>
<input name="tabs.{{key}}.name" id="tabs.{{key}}.name" type="text" value="{{tab.name}}" />
<label>Webhook</label>
<input name="tabs.{{key}}.webhook" id="tabs.{{key}}.webhook" type="password" value="{{tab.webhook}}" />
<input
style="display: none;"
name="tabs.{{key}}.id"
Expand Down

0 comments on commit 48dc04a

Please sign in to comment.