UNPKG

n8n-nodes-discord

Version:

nodes to trigger workflows from Discord or send interactive messages. Uses the components API which allows to create dialogs (e.g. attach buttons and wait for the user to click on them)

59 lines 3.46 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const uid_1 = require("uid"); const helpers_1 = require("../helpers"); const state_1 = __importDefault(require("../state")); async function default_1(client) { client.on('interactionCreate', (interaction) => { var _a, _b, _c; try { if (!interaction.isChatInputCommand()) return; if (!interaction.guildId) { interaction.reply({ content: 'Commands work only inside channels' }); return; } const userRoles = ((_a = interaction.member) === null || _a === void 0 ? void 0 : _a.roles).cache.map((role) => role.id); const input = interaction.options.getString('input'); if (state_1.default.channels[interaction.channelId] || state_1.default.channels.all) { [...((_b = state_1.default.channels[interaction.channelId]) !== null && _b !== void 0 ? _b : []), ...((_c = state_1.default.channels.all) !== null && _c !== void 0 ? _c : [])].forEach(async (trigger) => { if (trigger.type === 'command') { if (trigger.roleIds.length) { const hasRole = trigger.roleIds.some((role) => userRoles === null || userRoles === void 0 ? void 0 : userRoles.includes(role)); if (!hasRole) { interaction .reply({ content: 'You do not have permission', ephemeral: true }) .catch((e) => e); return; } } if (trigger.name === interaction.commandName) { (0, helpers_1.addLog)(`triggerWorkflow ${trigger.webhookId}`, client); const placeholderMatchingId = trigger.placeholder ? (0, uid_1.uid)() : ''; interaction .reply({ content: `/${interaction.commandName} sent`, ephemeral: true }) .catch((e) => e); const isEnabled = await (0, helpers_1.triggerWorkflow)(trigger.webhookId, null, placeholderMatchingId, state_1.default.baseUrl, interaction.user, interaction.channelId, undefined, undefined, undefined, undefined, input ? [input] : undefined, userRoles).catch((e) => e); if (isEnabled && trigger.placeholder) { const channel = client.channels.cache.get(interaction.channelId); const placeholder = await channel .send(trigger.placeholder) .catch((e) => (0, helpers_1.addLog)(`${e}`, client)); if (placeholder) (0, helpers_1.placeholderLoading)(placeholder, placeholderMatchingId, trigger.placeholder); } } } }); } } catch (e) { (0, helpers_1.addLog)(`${e}`, client); } }); } exports.default = default_1; //# sourceMappingURL=interactionCreateCmd.event.js.map