Skip to content

Commit

Permalink
📝 Add jsdoc to most files
Browse files Browse the repository at this point in the history
  • Loading branch information
ImDarkTom committed Nov 2, 2023
1 parent 0adfba8 commit f713269
Show file tree
Hide file tree
Showing 28 changed files with 215 additions and 47 deletions.
9 changes: 8 additions & 1 deletion src/buttons/action/cancelGeneration.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
//@ts-check
const { ButtonInteraction, Client } = require("discord.js");
const sendRequest = require("../../utils/SD/sendRequest");

module.exports = {
id: 'cancelGeneration',
ownerOnly: true,

callback: async (client, interaction) => {
/**
* Callback to cancel the generation of an image
* @param {Client} _client
* @param {ButtonInteraction} interaction
*/
callback: async (_client, interaction) => {
await sendRequest('sdapi/v1/interrupt', {}, "post");

interaction.reply({content: "Generating cancelled.", ephemeral: true});
Expand Down
10 changes: 9 additions & 1 deletion src/buttons/action/cancelUpscale.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
//@ts-check
const { ButtonInteraction, Client } = require("discord.js");

module.exports = {
id: 'cancelUpscale',
ownerOnly: true,

callback: async (client, interaction) => {
/**
*
* @param {Client} _client
* @param {ButtonInteraction} interaction
*/
callback: async (_client, interaction) => {
await interaction.message.delete();
},
};
9 changes: 8 additions & 1 deletion src/buttons/action/redoImage.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
//@ts-check
const imageDataFromEmbed = require("../../utils/SD/imageDataFromEmbed");
const sdConfig = require('../../../sdConfig.json');
const generateImage = require("../../utils/SD/generateImage");
const { Client, ButtonInteraction } = require("discord.js");

module.exports = {
id: 'redoImage',
ownerOnly: false,

callback: async (client, interaction) => {
/**
*
* @param {Client} _client
* @param {ButtonInteraction} interaction
*/
callback: async (_client, interaction) => {
const originalImageData = await imageDataFromEmbed(interaction.message.embeds[0]);

await generateImage(
Expand Down
18 changes: 15 additions & 3 deletions src/buttons/action/saveImageToDM.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
//@ts-check
const { Client, ButtonInteraction, User } = require("discord.js");

module.exports = {
id: 'saveImageToDM',
ownerOnly: false,

callback: async (client, interaction) => {
const msgToSaveEmbed = await interaction.channel.messages.fetch(interaction.message.content);
/**
*
* @param {Client} _client
* @param {ButtonInteraction} interaction
*/
callback: async (_client, interaction) => {
if (interaction.channel && interaction.member) {
const msgToSaveEmbed = await interaction.channel.messages.fetch(interaction.message.content);

interaction.member.user.send({content: "", embeds: [msgToSaveEmbed.embeds[0]]});
if (interaction.member.user instanceof User) {
interaction.member.user.send({content: "", embeds: [msgToSaveEmbed.embeds[0]]});
}
}
},
};
15 changes: 13 additions & 2 deletions src/buttons/action/upscaleImage.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,35 @@
//@ts-check
const imageDataFromEmbed = require('../../utils/SD/imageDataFromEmbed');
const sdConfig = require('../../../sdConfig.json');
const generateImage = require("../../utils/SD/generateImage");
const { Client, ButtonInteraction } = require('discord.js');

module.exports = {
id: 'upscaleImage',
ownerOnly: true,

callback: async (client, interaction) => {
/**
*
* @param {Client} _client
* @param {ButtonInteraction} interaction
*/
callback: async (_client, interaction) => {
const messageContent = String(interaction.message.content).split('-');

const upscaleMultiplier = Number(interaction.customId.split('-')[2]);

if (!interaction.channel) {
//Missing view channel intents
return;
}
const originalMessageEmbed = (await interaction.channel.messages.fetch(messageContent[0])).embeds[0];
const originalImageData = await imageDataFromEmbed(originalMessageEmbed, true);

interaction.message.delete();

let requestData;

if (sdConfig.useUltimateSDUpscale == true) {
if (sdConfig.useUltimateSdUpscale == true) {
requestData = {
"init_images": [originalImageData.image],
"denoising_strength": 0.2,
Expand Down
18 changes: 13 additions & 5 deletions src/buttons/pagination/sdInfoPagination.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
const { EmbedBuilder, ButtonBuilder, ActionRowBuilder, StringSelectMenuOptionBuilder, StringSelectMenuBuilder } = require("discord.js");
//@ts-check
const { EmbedBuilder, ButtonBuilder, ActionRowBuilder, StringSelectMenuOptionBuilder, StringSelectMenuBuilder, Client, ButtonInteraction } = require("discord.js");
const sendRequest = require("../../utils/SD/sendRequest");

module.exports = {
id: 'sdInfoPagination',
ownerOnly: false,

callback: async (client, interaction) => {
/**
*
* @param {Client} _client
* @param {ButtonInteraction} interaction
*/
callback: async (_client, interaction) => {
const direction = interaction.customId.split('-')[1];

const originalMessage = interaction.message;
Expand All @@ -14,6 +20,7 @@ module.exports = {

const [prevButton, nextButton] = originalComponents[1].components.map((originalButton) => new ButtonBuilder(originalButton.data));

//@ts-ignore
const [modelType, page, totalPages, modelAmount] = originalEmbed.data.footer.text.split('.');


Expand All @@ -27,7 +34,7 @@ module.exports = {

if (newPage == 1) {
prevButton.setDisabled(true);
} else if (newPage == totalPages) {
} else if (newPage == Number(totalPages)) {
nextButton.setDisabled(true);
} else {
prevButton.setDisabled(false);
Expand Down Expand Up @@ -71,7 +78,7 @@ module.exports = {
for (const item of hypernetsList) {
const hypernetName = item.name;

select.addOptions(
newSelectComponent.addOptions(
new StringSelectMenuOptionBuilder()
.setLabel(hypernetName)
.setDescription(`<hypernet:${hypernetName}:1>`)
Expand All @@ -86,7 +93,7 @@ module.exports = {
const embeddingsList = embeddingNames.slice(startIndex, endIndex);

for (const name of embeddingsList) {
select.addOptions(
newSelectComponent.addOptions(
new StringSelectMenuOptionBuilder()
.setLabel(name)
.setDescription(name)
Expand All @@ -99,6 +106,7 @@ module.exports = {
const newSelectComponentRow = new ActionRowBuilder()
.addComponents(newSelectComponent)

//@ts-ignore
originalMessage.edit({content: "", embeds: [originalEmbed], components: [newSelectComponentRow, newButtonRow]});

interaction.deferUpdate();
Expand Down
12 changes: 10 additions & 2 deletions src/buttons/selection/saveImage.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
const { ActionRowBuilder, ButtonBuilder, ButtonStyle } = require('discord.js');
//@ts-check
const { ActionRowBuilder, ButtonBuilder, ButtonStyle, Client, ButtonInteraction } = require('discord.js');

module.exports = {
id: 'saveImage',
ownerOnly: false,

callback: async (client, interaction) => {
/**
*
* @param {Client} _client
* @param {ButtonInteraction} interaction
*/
callback: (_client, interaction) => {
const interactionMsg = interaction.message;

const downloadBtn = new ButtonBuilder()
//@ts-ignore
.setURL(interaction.message.embeds[0].image.url)
.setLabel('Download')
.setStyle(ButtonStyle.Link)
Expand All @@ -21,6 +28,7 @@ module.exports = {
const row = new ActionRowBuilder()
.addComponents(downloadBtn, saveToDM)

//@ts-ignore
interaction.reply({content: interactionMsg.id, ephemeral: true, components: [row]});
},
};
11 changes: 9 additions & 2 deletions src/buttons/selection/upscaleImageMenu.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
const { ButtonStyle, ButtonBuilder, ActionRowBuilder, StringSelectMenuBuilder } = require("discord.js");
//@ts-check
const { ButtonStyle, ButtonBuilder, ActionRowBuilder, StringSelectMenuBuilder, ButtonInteraction, Client } = require("discord.js");
const sdConfig = require("../../../sdConfig.json");

module.exports = {
id: 'upscaleImageMenu',
ownerOnly: false,

callback: async (client, interaction) => {
/**
*
* @param {Client} _client
* @param {ButtonInteraction} interaction
*/
callback: async (_client, interaction) => {
const interactionMsg = interaction.message;

const upscale2x = new ButtonBuilder()
Expand Down Expand Up @@ -46,6 +52,7 @@ module.exports = {
const selectionRow = new ActionRowBuilder()
.addComponents(dropdown)

//@ts-ignore
interaction.reply({content: `${interactionMsg.id}-${sdConfig.generationDefaults.defaultUpscalerIndex}`, ephemeral: false, components: [selectionRow, row]});
},
};
4 changes: 3 additions & 1 deletion src/commands/imageCreation/controlNet.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,11 @@ module.exports = {

/**
*
* @param {Client} _client
* @param {ChatInputCommandInteraction} interaction
* @returns
*/
callback: async (client, interaction) => {
callback: async (_client, interaction) => {
if (sdConfig.extensionConfigs.controlnet.enabled == false) {
await interaction.reply({content: "Controlnet is disabled, you can enable it in the `sdConfig.json` file."});
return;
Expand Down
9 changes: 7 additions & 2 deletions src/commands/imageCreation/generate.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { ApplicationCommandOptionType } = require('discord.js');
const { ApplicationCommandOptionType, Client, ChatInputCommandInteraction } = require('discord.js');
const sdConfig = require('../../../sdConfig.json');
const generateImage = require('../../utils/SD/generateImage');

Expand Down Expand Up @@ -31,7 +31,12 @@ module.exports = {
}
],

callback: async (client, interaction) => {
/**
*
* @param {Client} _client
* @param {ChatInputCommandInteraction} interaction
*/
callback: async (_client, interaction) => {
await generateImage(
'sdapi/v1/txt2img',
{
Expand Down
7 changes: 7 additions & 0 deletions src/commands/misc/ping.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const { Client, ChatInputCommandInteraction } = require("discord.js");

module.exports = {
name: 'ping',
description: 'Pong! Checks the bot ping.',
Expand All @@ -6,6 +8,11 @@ module.exports = {
// options: Object[],
// deleted: Boolean,

/**
*
* @param {Client} client
* @param {ChatInputCommandInteraction} interaction
*/
callback: (client, interaction) => {
interaction.reply(`Pong! ${client.ws.ping}ms`);
},
Expand Down
9 changes: 7 additions & 2 deletions src/commands/sdInfo/changeModel.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { EmbedBuilder, ActionRowBuilder, StringSelectMenuBuilder } = require("discord.js");
const { EmbedBuilder, ActionRowBuilder, StringSelectMenuBuilder, Client, ChatInputCommandInteraction } = require("discord.js");
const sdConfig = require('../../../sdConfig.json')
const sendRequest = require("../../utils/SD/sendRequest");

Expand All @@ -9,7 +9,12 @@ module.exports = {
// testOnly: Boolean,
// deleted: Boolean,

callback: async (client, interaction) => {
/**
*
* @param {Client} _client
* @param {ChatInputCommandInteraction} interaction
*/
callback: async (_client, interaction) => {
let modelList = [];
let embed;
const modelsResponse = await sendRequest('sdapi/v1/sd-models', {}, "get");
Expand Down
11 changes: 8 additions & 3 deletions src/commands/sdInfo/sdInfo.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { ApplicationCommandOptionType, EmbedBuilder, StringSelectMenuBuilder, StringSelectMenuOptionBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle } = require("discord.js");
const { ApplicationCommandOptionType, EmbedBuilder, StringSelectMenuBuilder, StringSelectMenuOptionBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle, Client, ChatInputCommandInteraction } = require("discord.js");
const sendRequest = require("../../utils/SD/sendRequest");

module.exports = {
Expand All @@ -25,8 +25,13 @@ module.exports = {
],
// deleted: Boolean,

callback: async (client, interaction) => {
const subcommandName = interaction.options._subcommand;
/**
*
* @param {Client} _client
* @param {ChatInputCommandInteraction} interaction
*/
callback: async (_client, interaction) => {
const subcommandName = interaction.options.getSubcommand();

const select = new StringSelectMenuBuilder()
.setCustomId(`sdInfoDetailDropdown-${subcommandName}`)
Expand Down
8 changes: 8 additions & 0 deletions src/events/interactionCreate/handleButtons.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
//@ts-check
const { Client } = require('discord.js');
const getLocalButtons = require('../../utils/getLocalButtons');

/**
*
* @param {Client} client
* @param {import('discord.js').Interaction} interaction
* @returns
*/
module.exports = async (client, interaction) => {
if (!interaction.isButton()) return;

Expand Down
7 changes: 7 additions & 0 deletions src/events/interactionCreate/handleCommands.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
const { Client } = require('discord.js');
const { devs, testServer } = require('../../../botConfig.json');
const getLocalCommands = require('../../utils/getLocalCommands');

/**
*
* @param {Client} client
* @param {import('discord.js').Interaction} interaction
* @returns
*/
module.exports = async (client, interaction) => {
if (!interaction.isChatInputCommand()) return;

Expand Down
7 changes: 7 additions & 0 deletions src/events/interactionCreate/handleSelectMenu.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
const { Client } = require('discord.js');
const getLocalSelectMenus = require('../../utils/getLocalSelectMenus');

/**
*
* @param {Client} client
* @param {import('discord.js').Interaction} interaction
* @returns
*/
module.exports = async (client, interaction) => {
if (!interaction.isStringSelectMenu()) return;

Expand Down
5 changes: 5 additions & 0 deletions src/events/ready/01registerCommands.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
const { Client } = require('discord.js');
const { testServer } = require('../../../botConfig.json');
const areCommandsDifferent = require('../../utils/areCommandsDifferent');
const getApplicationCommands = require('../../utils/getApplicationCommands');
const getLocalCommands = require('../../utils/getLocalCommands');

/**
*
* @param {Client} client
*/
module.exports = async (client) => {
try {
const localCommands = getLocalCommands();
Expand Down
Loading

0 comments on commit f713269

Please sign in to comment.