djs-systems
Version:
The simplest way to build complex Discord bots.
110 lines (109 loc) • 5.06 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ghostPing = void 0;
const discord_js_1 = require("discord.js");
const error_1 = require("./error");
const misc_1 = require("./misc");
// ------------------------------
// ------ F U N C T I O N -------
// ------------------------------
/**
* A Great system to see **who ghost pinged**
*
* **Important!**: Use it in `messageDelete` event
*
* @param message
* @param options
* @link `Documentation:` https://simplyd.js.org/docs/general/ghostPing
* @example simplydjs.ghostPing(message)
*/
async function ghostPing(message, options = { strict: false }) {
return new Promise(async (resolve) => {
message
.fetch(true)
.then((m) => {
if (m) {
if (options.strict)
throw new error_1.SimplyError({
function: 'ghostPing',
title: 'Use this function in messageDelete event',
tip: 'We recognised that you are not using this function in messageDelete event.'
});
else
console.log(`SimplyError - ghostPing | Error: Use this function in messageDelete event\n\nWe recognised that you are not using this function in messageDelete event.`);
}
})
.catch((_err) => {
return true;
});
if (message.mentions.users.first()) {
try {
if (message.author.bot)
return;
if (message.content.includes(`<@${message.mentions.members.first()?.user.id}>`) ||
message.content.includes(`<@!${message.mentions.members.first()?.user.id}>`)) {
if (!options.embed) {
options.embed = {
footer: {
text: '©️ Rahuletto. npm i simply-djs',
iconURL: 'https://i.imgur.com/XFUIwPh.png'
},
color: (0, misc_1.toRgb)('#406DBC')
};
}
const embed = new discord_js_1.EmbedBuilder()
.setAuthor(options.embed?.author || {
name: message.author.username,
iconURL: message.author.displayAvatarURL({
forceStatic: false
})
})
.setTitle(options.embed?.title || 'Ghost Ping')
.setDescription(options.embed?.description ||
`${message.author} **(${message.author.username})** just ghost pinged ${message.mentions.members.first()} **(${message.mentions.users.first().username})**\n\nContent: **${message.content}**`)
.setColor(options.embed?.color || (0, misc_1.toRgb)('#406DBC'))
.setFooter(options.embed?.footer
? options.embed?.footer
: {
text: '©️ Rahuletto. npm i simply-djs',
iconURL: 'https://i.imgur.com/XFUIwPh.png'
})
.setTimestamp();
if (options?.embed?.fields)
embed.setFields(options.embed?.fields);
if (options?.embed?.author)
embed.setAuthor(options.embed?.author);
if (options?.embed?.image)
embed.setImage(options.embed?.image);
if (options?.embed?.thumbnail)
embed.setThumbnail(options.embed?.thumbnail);
if (options?.embed?.timestamp)
embed.setTimestamp(options.embed?.timestamp);
if (options?.embed?.title)
embed.setTitle(options.embed?.title);
if (options?.embed?.url)
embed.setURL(options.embed?.url);
message.channel
.send({ embeds: [embed] })
.then(async (msg) => {
setTimeout(() => {
msg.delete();
}, (0, misc_1.ms)('20s'));
resolve(message.mentions.users.first());
});
}
}
catch (err) {
if (options?.strict)
throw new error_1.SimplyError({
function: 'ghostPing',
title: 'An Error occured when running the function ',
tip: err.stack
});
else
console.log(`SimplyError - ghostPing | Error: ${err.stack}`);
}
}
});
}
exports.ghostPing = ghostPing;