djs-systems
Version:
The simplest way to build complex Discord bots.
156 lines (155 loc) • 8.51 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.bumpReminder = void 0;
const discord_js_1 = require("discord.js");
const bumpReminder_1 = __importDefault(require("./model/bumpReminder"));
const misc_1 = require("./misc");
const error_1 = require("./error");
// ------------------------------
// ------ F U N C T I O N -------
// ------------------------------
/**
* A Very cool bump reminder system that reminds when a bump is necessary [Only Disboard].
*
* **Requires you to have this in `messageCreate` and `ready` event**
* @param client
* @param message
* @param options
* @link `Documentation:` https://simplyd.js.org/docs/systems/bumpReminder
* @example simplydjs.bumpReminder(client, message)
*/
async function bumpReminder(client, message, options) {
try {
if (!options && message)
options = message;
if (options == message || (!options && !message)) {
return new Promise(async (resolve) => {
setInterval(async () => {
const data = await bumpReminder_1.default.find({});
data.forEach(async (dt) => {
if (dt.nextBump && dt.nextBump < Date.now()) {
dt.nextBump = undefined;
await dt.save().catch(() => { });
const cho = await client.channels.fetch(dt.channel, {
force: true
});
const reminder = new discord_js_1.EmbedBuilder()
.setTitle(options.embed?.remind?.title || 'Bump Reminder !')
.setDescription(options.embed?.remind?.description ||
'Its been 2 hours since last bump. Reminding the server members to bump again.\nDo /bump to bump the server ;)')
.setTimestamp()
.setColor(options.embed?.remind?.color || (0, misc_1.toRgb)('#406DBC'))
.setFooter(options.embed?.remind?.footer || {
text: '©️ Rahuletto. npm i simply-djs',
iconURL: 'https://i.imgur.com/XFUIwPh.png'
});
if (options?.embed?.remind?.fields)
reminder.setFields(options.embed?.remind?.fields);
if (options?.embed?.remind?.author)
reminder.setAuthor(options.embed?.remind?.author);
if (options?.embed?.remind?.image)
reminder.setImage(options.embed?.remind?.image);
if (options?.embed?.remind?.thumbnail)
reminder.setThumbnail(options.embed?.remind?.thumbnail);
if (options?.embed?.remind?.timestamp)
reminder.setTimestamp(options.embed?.remind?.timestamp);
if (options?.embed?.remind?.title)
reminder.setTitle(options.embed?.remind?.title);
if (options?.embed?.remind?.url)
reminder.setURL(options.embed?.remind?.url);
await cho.send({
content: message.content || '\u200b',
embeds: [reminder]
});
resolve(true);
}
else
return;
});
}, (0, misc_1.ms)('10s'));
});
}
if (options?.toggle == false)
return;
let chid = [];
if (options && message.channel) {
return new Promise(async (resolve) => {
if (Array.isArray(options?.channelId)) {
chid = options?.channelId;
}
else if (!Array.isArray(options?.channelId)) {
chid.push(options?.channelId);
}
if (message.author.id === '302050872383242240') {
for (let i = 0; i < chid.length; i++) {
if (message.channel.id === chid[i]) {
if (message.embeds[0] &&
message.embeds[0].description &&
message.embeds[0].description.includes('Bump done')) {
const timeout = (0, misc_1.ms)('2h');
const time = Date.now() + timeout;
let data = await bumpReminder_1.default.findOne({
channel: chid[i]
});
if (!data) {
data = new bumpReminder_1.default({
counts: [],
guild: message.guild.id,
channel: chid[i],
nextBump: time
});
await data.save().catch(() => { });
}
data.nextBump = time;
await data.save().catch(() => { });
const thankyou = new discord_js_1.EmbedBuilder()
.setTitle(options.embed?.thank?.title || 'Thank you for bump!')
.setDescription(options.embed?.thank?.description ||
'Thank you for bumping the server. This means a lot. Will notify everyone after 2 hours (120 minutes)')
.setTimestamp()
.setColor(options.embed?.thank?.color || (0, misc_1.toRgb)('#209120'))
.setFooter(options.embed?.thank?.footer || {
text: ' ©️ Rahuletto. npm i simply-djs',
iconURL: 'https://i.imgur.com/XFUIwPh.png'
});
if (options?.embed?.thank?.fields)
thankyou.setFields(options.embed?.thank?.fields);
if (options?.embed?.thank?.author)
thankyou.setAuthor(options.embed?.thank?.author);
if (options?.embed?.thank?.image)
thankyou.setImage(options.embed?.thank?.image);
if (options?.embed?.thank?.thumbnail)
thankyou.setThumbnail(options.embed?.thank?.thumbnail);
if (options?.embed?.thank?.timestamp)
thankyou.setTimestamp(options.embed?.thank?.timestamp);
if (options?.embed?.thank?.title)
thankyou.setTitle(options.embed?.thank?.title);
if (options?.embed?.thank?.url)
thankyou.setURL(options.embed?.thank?.url);
await message.channel.send({
content: options?.content || '\u200b',
embeds: [thankyou]
});
resolve(true);
}
}
}
}
});
}
}
catch (err) {
if (options?.strict)
throw new error_1.SimplyError({
function: 'bumpReminder',
title: 'An Error occured when running the function ',
tip: err.stack
});
else
console.log(`SimplyError - bumpReminder | Error: ${err.stack}`);
}
}
exports.bumpReminder = bumpReminder;