mirror of
https://github.com/pieartsy/PluralFlux.git
synced 2026-04-16 17:45:28 +10:00
adding docstrings
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user