n8n-nodes-base
Version:
Base nodes of n8n
84 lines • 3.15 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.description = void 0;
exports.execute = execute;
const descriptions_1 = require("../../../../../utils/descriptions");
const utilities_1 = require("../../../../../utils/utilities");
const utils_1 = require("../../helpers/utils");
const transport_1 = require("../../transport");
const common_description_1 = require("../common.description");
const properties = [
common_description_1.channelRLC,
...descriptions_1.returnAllOrLimit,
{
displayName: 'Options',
name: 'options',
type: 'collection',
placeholder: 'Add option',
default: {},
options: [common_description_1.simplifyBoolean],
},
];
const displayOptions = {
show: {
resource: ['message'],
operation: ['getAll'],
},
hide: {
authentication: ['webhook'],
},
};
exports.description = (0, utilities_1.updateDisplayOptions)(displayOptions, properties);
async function execute(_guildId, userGuilds) {
const returnData = [];
const items = this.getInputData();
const simplifyResponse = (0, utils_1.createSimplifyFunction)([
'id',
'channel_id',
'author',
'content',
'timestamp',
'type',
]);
const getChannelId = await utils_1.setupChannelGetter.call(this, userGuilds);
for (let i = 0; i < items.length; i++) {
try {
const channelId = await getChannelId(i);
const returnAll = this.getNodeParameter('returnAll', i, false);
const qs = {};
let response = [];
if (!returnAll) {
const limit = this.getNodeParameter('limit', 0);
qs.limit = limit;
response = await transport_1.discordApiRequest.call(this, 'GET', `/channels/${channelId}/messages`, undefined, qs);
}
else {
let responseData;
qs.limit = 100;
do {
responseData = await transport_1.discordApiRequest.call(this, 'GET', `/channels/${channelId}/messages`, undefined, qs);
if (!responseData?.length)
break;
qs.before = responseData[responseData.length - 1].id;
response.push(...responseData);
} while (responseData.length);
}
const simplify = this.getNodeParameter('options.simplify', i, false);
if (simplify) {
response = response.map(simplifyResponse);
}
const executionData = this.helpers.constructExecutionMetaData(this.helpers.returnJsonArray(response), { itemData: { item: i } });
returnData.push(...executionData);
}
catch (error) {
const err = utils_1.parseDiscordError.call(this, error, i);
if (this.continueOnFail()) {
returnData.push(...utils_1.prepareErrorData.call(this, err, i));
continue;
}
throw err;
}
}
return returnData;
}
//# sourceMappingURL=getAll.operation.js.map