(sock, message, args, context)
| 145 | description: 'Schedule a message to be sent later in this chat', |
| 146 | usage: '.schedule <time> <message>\nTime: 10m | 2h | 1h30m | 14:30 | 10:30am', |
| 147 | async handler(sock, message, args, context) { |
| 148 | const chatId = context.chatId || message.key.remoteJid; |
| 149 | const senderId = context.senderId || message.key.remoteJid; |
| 150 | const channelInfo = context.channelInfo || {}; |
| 151 | // Start engine with current sock |
| 152 | startSchedulerEngine(sock); |
| 153 | if (!args || args.length < 2) { |
| 154 | return await sock.sendMessage(chatId, { |
| 155 | text: `*⏰ SCHEDULE A MESSAGE*\n\n` + |
| 156 | `*Usage:*\n\`.schedule <time> <message>\`\n\n` + |
| 157 | `*Time formats:*\n` + |
| 158 | `• \`10m\` → in 10 minutes\n` + |
| 159 | `• \`2h\` → in 2 hours\n` + |
| 160 | `• \`1h30m\` → in 1 hour 30 minutes\n` + |
| 161 | `• \`14:30\` → today at 2:30 PM\n` + |
| 162 | `• \`10:30am\` → today at 10:30 AM\n\n` + |
| 163 | `*Examples:*\n` + |
| 164 | `\`.schedule 10m Good morning everyone!\`\n` + |
| 165 | `\`.schedule 2h Team meeting starting now!\`\n` + |
| 166 | `\`.schedule 14:30 Don't forget the call!\``, |
| 167 | ...channelInfo |
| 168 | }, { quoted: message }); |
| 169 | } |
| 170 | const timeInput = args[0]; |
| 171 | const msgText = args.slice(1).join(' ').trim(); |
| 172 | if (!msgText) { |
| 173 | return await sock.sendMessage(chatId, { |
| 174 | text: '❌ Please provide a message after the time.\n\nExample: `.schedule 10m Hello!`', |
| 175 | ...channelInfo |
| 176 | }, { quoted: message }); |
| 177 | } |
| 178 | const targetDate = parseTime(timeInput); |
| 179 | if (!targetDate) { |
| 180 | return await sock.sendMessage(chatId, { |
| 181 | text: `❌ Invalid time format: *${timeInput}*\n\nValid: \`10m\` \`2h\` \`1h30m\` \`14:30\` \`10:30am\``, |
| 182 | ...channelInfo |
| 183 | }, { quoted: message }); |
| 184 | } |
| 185 | const schedules = await loadSchedules(); |
| 186 | const newItem = { |
| 187 | id: generateId(), |
| 188 | chatId, |
| 189 | senderId, |
| 190 | message: msgText, |
| 191 | sendAt: targetDate.getTime(), |
| 192 | createdAt: Date.now() |
| 193 | }; |
| 194 | schedules.push(newItem); |
| 195 | await saveSchedules(schedules); |
| 196 | const timeLeft = formatTimeLeft(targetDate.getTime() - Date.now()); |
| 197 | const timeStr = targetDate.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' }); |
| 198 | await sock.sendMessage(chatId, { |
| 199 | text: `✅ *Message Scheduled!*\n\n` + |
| 200 | `📌 *ID:* ${newItem.id}\n` + |
| 201 | `⏳ *Sends in:* ${timeLeft} (at ${timeStr})\n` + |
| 202 | `💬 *Message:* ${msgText}\n\n` + |
| 203 | `_Use .schedulecancel ${newItem.id} to cancel_`, |
| 204 | ...channelInfo |
nothing calls this directly
no test coverage detected