Download src/commands/manager-command/check-countdown.js from vanducdev/botzalo: direct link, hf CLI and curl.
- Browser
- Download file 1.69 kB
-
https://huggingface.co/spaces/vanducdev/botzalo/resolve/main/src/commands/manager-command/check-countdown.js
- Command line
-
hf download hf://spaces/vanducdev/botzalo/src/commands/manager-command/check-countdown.js
-
curl -L -o check-countdown.js https://huggingface.co/spaces/vanducdev/botzalo/resolve/main/src/commands/manager-command/check-countdown.js
1.69 kB
| import schedule from 'node-schedule'; | |
| import fs from 'fs/promises'; | |
| import path from 'path'; | |
| const countdownJobs = new Map(); | |
| const groupSettingsPath = path.resolve('./assets/data/group_settings.json'); | |
| async function isBotActive(threadId) { | |
| try { | |
| const data = await fs.readFile(groupSettingsPath, 'utf-8'); | |
| const groupSettings = JSON.parse(data); | |
| return groupSettings[threadId]?.activeBot === true; | |
| } catch (error) { | |
| console.error('Lỗi đọc group_settings.json:', error); | |
| return false; | |
| } | |
| } | |
| export async function sendReactionWaitingCountdown(api, message, count) { | |
| const messages = Array(count).fill(message); | |
| const messageId = message.data.cliMsgId || Date.now().toString(); | |
| const threadId = message.threadId || message.data?.threadId; | |
| const isActive = await isBotActive(threadId); | |
| if (!isActive) { | |
| return; | |
| } | |
| const date = new Date(Date.now() + 300); | |
| const job = schedule.scheduleJob(date, async () => { | |
| try { | |
| while (messages.length > 0) { | |
| try { | |
| await api.addReaction("CLOCK", messages); | |
| await new Promise(resolve => setTimeout(resolve, 1000)); | |
| await api.addReaction("UNDO", messages); | |
| } catch (error) { | |
| } | |
| messages.splice(0, 1); | |
| } | |
| } catch (error) { | |
| console.error(`Error in countdown job ${messageId}:`, error); | |
| } finally { | |
| job.cancel(); | |
| countdownJobs.delete(messageId); | |
| } | |
| }); | |
| countdownJobs.set(messageId, job); | |
| } | |