adding docstrings

This commit is contained in:
Aster Fialla
2026-02-13 21:23:33 -05:00
parent b71eb90eb1
commit 01c747b5d5
3 changed files with 130 additions and 19 deletions

View File

@@ -1,14 +1,29 @@
const wh = {};
/**
* Gets or creates a webhook.
*
* @param api - The discord.js API.
* @param {string} channelId - The channel the message was sent in.
* @returns {Object} A webhook object.
*/
wh.getOrCreateWebhook = async function (api, channelId) {
const name = 'PluralFlux Proxy Webhook';
let webhook = await getWebhook(api, channelId, name);
if (webhook === undefined) {
if (!webhook) {
webhook = await api.channels.createWebhook(channelId, {name: name});
}
return webhook;
}
/**
* Gets an existing webhook.
*
* @param api - The discord.js API.
* @param {string} channelId - The channel the message was sent in.
* @param {string} name - The name of the webhook.
* @returns {Object} A webhook object.
*/
async function getWebhook(api, channelId, name) {
const allWebhooks = await api.channels.getWebhooks(channelId);
if (allWebhooks.length === 0) {
@@ -23,6 +38,14 @@ async function getWebhook(api, channelId, name) {
return pf_webhook;
}
/**
* Replaces a proxied message with a webhook using the member information.
*
* @param api - The discord.js API.
* @param data - The discord.js data.
* @param {string} text - The text to send via the webhook.
* @param {Object} member - A member object from the database.
*/
wh.replaceMessage = async function (api, data, text, member) {
if (text.length > 0) {
const webhook = await wh.getOrCreateWebhook(api, data.channel_id);