Skip to content

Instantly share code, notes, and snippets.

@KOULIKS94
Created March 24, 2025 14:05
Show Gist options
  • Select an option

  • Save KOULIKS94/ed8b826b9b78dae7088d8d801f807697 to your computer and use it in GitHub Desktop.

Select an option

Save KOULIKS94/ed8b826b9b78dae7088d8d801f807697 to your computer and use it in GitHub Desktop.
const { bot, isAdmin } = require('../lib');
let autoReviveGroups = {}; // Stores groups with auto-revive enabled
let lastMessageTime = {}; // Tracks last message time
const reviveMessages = [
"πŸ”₯ *Wake up everyone! This group needs some energy!*",
"⚑ *Where is everyone? Drop a message now!*",
"πŸš€ *This group was silent for too long. Let’s chat!*",
"πŸ‘€ *Silent readers, it's time to talk!*",
"πŸ—£ *Reviving the chat! Who's online?*"
];
// Enable or disable auto-revive
bot(
{
pattern: 'autorevive',
desc: 'Enable or disable auto-revive feature',
type: 'group',
},
async (message, match) => {
if (!(await isAdmin(message))) {
return await message.send('*You must be an admin to use this command!*');
}
if (match.toLowerCase() === 'on') {
autoReviveGroups[message.jid] = true;
lastMessageTime[message.jid] = Date.now(); // Set initial time
await message.send('βœ… *Auto-Revive is now enabled!*');
} else if (match.toLowerCase() === 'off') {
autoReviveGroups[message.jid] = false;
await message.send('🚫 *Auto-Revive is now disabled!*');
} else {
await message.send('*Usage: !autorevive on/off*');
}
}
);
// Track last message time
bot(
{
on: 'message',
},
async (message) => {
if (message.jid && !message.fromMe) {
lastMessageTime[message.jid] = Date.now();
}
}
);
// Auto-Revive Mechanism (Runs Every 6 Hours)
setInterval(async () => {
const currentTime = Date.now();
for (let groupJid in autoReviveGroups) {
if (autoReviveGroups[groupJid]) {
const lastActive = lastMessageTime[groupJid] || 0;
const timeDiff = currentTime - lastActive;
if (timeDiff > 6 * 60 * 60 * 1000) { // 6 hours
const groupMetadata = await bot.client.groupMetadata(groupJid);
const mentions = groupMetadata.participants.map((user) => user.id);
const reviveMessage = reviveMessages[Math.floor(Math.random() * reviveMessages.length)];
await bot.client.sendMessage(groupJid, { text: `⚑ ${reviveMessage}`, mentions });
lastMessageTime[groupJid] = currentTime; // Reset timer
}
}
}
}, 10 * 60 * 1000); // Check every 10 minutes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment