Quick actions

cmd+k|ctrl+k

Navigation

Languages

Utilites

Snippet info

Language

TypeScript

Visibility

public

Author

baller6969

Created

2024-01-08T09:13:35.09287Z

Updated

2024-01-08T09:13:35.09287Z

import { ColorResolvable, EmbedBuilder, WebhookClient } from 'discord.js';

/**

 * Logs an informational message to the console.

 * @param {any} message - The message to be logged.

 * @returns {void}

 */

function info(message: any): void {

	console.log(`\x1b[34m\u2139 ${message}\x1b[0m`);

}



/**

 * Logs a success message to the console.

 * @param {any} message - The message to be logged.

 * @returns {void}

 */

function done(message: any): void {

	console.log(`\x1b[32m\u2705 ${message}\x1b[0m`);

}



/**

 * Logs a warning message to the console.

 * @param {any} message - The message to be logged.

 * @returns {void}

 */

function warn(message: any): void {

	console.log(`\x1b[33m\u26a0 ${message}\x1b[0m`);

}



/**

 * Logs an error message to the console.

 * @param {any} message - The message to be logged.

 * @returns {void}

 */

function error(message: any): void {

	console.log(`\x1b[31m\u26D4 ${message}\x1b[0m`);

}



/**

 * Logs a debug message to the console.

 * @param {any} message - The message to be logged.

 * @returns {void}

 */

function debug(message: any): void {

	console.log(`\x1b[35m\u1367 ${message}\x1b[0m`);

}



/**

 * Logger object containing various logging functions.

 */

export const logger = {

	info,

	done,

	warn,

	error,

	debug,

};



/**

 * Sends a loading message as a reply to a Discord interaction.

 * @async

 * @returns {Promise<EmbedBuilder>} A promise that resolves with the loading message embed.

 */

export async function loading(): Promise<EmbedBuilder> {

	const loadingEmbed = new EmbedBuilder()

		.setDescription('Loading... <a:wumpusdance:1189474658060341278>')

		.setColor('Blurple')

		.setFooter({ text: 'Taking too long? Use the command / interaction again to retry.' });



	return loadingEmbed;

}



/**

 * Sends an error message as an embed to a Discord interaction.

 * @async

 * @returns {Promise<EmbedBuilder>} A promise that resolves with the error message embed.

 */

export async function errormsg(error_message?: any): Promise<EmbedBuilder> {

	if (!error_message) {

		const errorEmbed = new EmbedBuilder()

			.setTitle('An error occurred!')

			.setDescription(`WHAT NOW!? Well, you can try using the command / interaction again.`)

			.setFooter({ text: 'If this error persists, please DM icmecodes.' })

			.setColor('Red');



		return errorEmbed;

	} else {

		const errorEmbed = new EmbedBuilder()

			.setTitle('An error occurred!')

			.setDescription(

				`WHAT NOW!? Well, you can try using the command / interaction again.\n\n\`\`\`shell\n${error_message}\n\`\`\``,

			)

			.setFooter({ text: 'If this error persists, please DM icmecodes.' })

			.setColor('Red');



		return errorEmbed;

	}

}



/**

 * Options for sending an embed.

 * @interface

 * @property {string} message - The message for the embed.

 * @property {string} [title] - The title for the embed.

 * @property {string} [footer] - The footer for the embed.

 * @property {string} [thumbnail] - The thumbnail for the embed.

 * @property {string} [image] - The image for the embed.

 * @property {boolean} [timestamp] - Whether to include a timestamp in the embed.

 * @property {ColorResolvable} [color] - The color for the embed.

 */

interface sendEmbedOptions {

	message: string;

	title?: string;

	footer?: string;

	thumbnail?: string;

	image?: string;

	timestamp?: boolean;

	color?: ColorResolvable;

}



/**

 * Sends a generic embed to a Discord interaction with optional settings.

 * @async

 * @param {sendEmbedOptions} options - The options for the embed.

 * @returns {Promise<EmbedBuilder>} A promise that resolves with the generated embed.

 */

export async function embed(options: sendEmbedOptions): Promise<EmbedBuilder> {

	const embed = new EmbedBuilder().setDescription(options.message);



	if (options.color) {

		embed.setColor(options.color);

	} else {

		embed.setColor('Blurple');

	}



	if (options.title) {

		embed.setTitle(options.title);

	}



	if (options.footer) {

		embed.setFooter({ text: options.footer });

	}



	if (options.thumbnail) {

		embed.setThumbnail(options.thumbnail);

	}



	if (options.image) {

		embed.setImage(options.image);

	}



	if (options.timestamp) {

		embed.setTimestamp();

	}



	return embed;

}



/**

 * Generates a code block.

 * @function

 * @param {string} text - The text to be included in the code block.

 * @param {string} [style] - The style of the code block.

 * @returns {string} The generated code block.

 */

export function codeblock(text: string, style?: string): string {

	if (!style) {

		return `\`\`\`\n${text}\n\`\`\``;

	} else {

		return `\`\`\`${style}\n${text}\n\`\`\``;

	}

}



/**

 * Extracts fluxus HWID from a URL.

 * @function

 * @param {string} url - The URL to extract the HWID from.

 * @returns {string} The extracted HWID.

 */

export function extractHwid(url: string) {

	const regex = /HWID=([0-9a-zA-Z]+)/;

	const match = url.match(regex);



	return match ? match[1] : url;

}



/**

 * Options for sending an error log.

 * @interface

 * @property {string} error - The error to send.

 * @property {string} [url] - The URL to send the error log to.

 */

interface sendErrorLogOptions {

	error: string;

}



/**

 * Sends an error log as an embed to a specified Discord webhook.

 * @async

 * @param {sendErrorLogOptions} options - The options for sending the error log.

 * @returns {Promise<void>} A promise that resolves once the error log is sent.

 */

export async function sendErrorLog(options: sendErrorLogOptions): Promise<void> {

	const webhook = new WebhookClient({

		url: 'https://discord.com/api/webhooks/1189463959699476580/nbLPS8RlBqJgPXFfp62di9NhFDvp4XTn22onHOYDhwC7SLD78TpPT7HNme2FwwJ86vPc',

	});



	webhook.send({

		embeds: [await embed({ message: `${codeblock(options.error, 'shell')}` })],

	});

}



/**

 * Check if a given value is a valid hex color code.

 *

 * @param {string} hex - The hex color code to be validated.

 * @returns {boolean} Returns true if the input is a valid hex color code, otherwise false.

 */

export function isHex(hex: string): boolean {
    
}
INFO