forked from AyGemuy/Taylor-V2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdateTask.js
More file actions
42 lines (42 loc) · 1.79 KB
/
Copy pathupdateTask.js
File metadata and controls
42 lines (42 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import fs from "fs";
import path from "path";
import {
fileURLToPath
} from "url";
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const taskFilePath = path.join(__dirname, "../../json/task/coding.json");
let taskData = JSON.parse(fs.readFileSync(taskFilePath));
const validStatuses = ["Pending", "In Progress", "Completed"];
let handler = async (m, {
conn,
text,
usedPrefix,
command
}) => {
if (!m.chat.endsWith("@g.us")) {
return;
}
if (!text) {
return conn.sendMessage(m.chat, {
text: `🚨 *Usage:* Send command *${usedPrefix + command} [task ID] [new status]*\nExample: *${usedPrefix + command} 1 Completed* 🚨`,
quoted: m
});
}
const [taskId, ...statusParts] = text.split(" ");
const newStatus = statusParts.join(" ").toLowerCase();
if (!validStatuses.map(status => status.toLowerCase()).includes(newStatus)) {
return conn.reply(m.chat, `Invalid status. Please use one of the following: ${validStatuses.join(", ")}.`, m);
}
const taskIndex = taskData.task.findIndex(task => task.id === parseInt(taskId));
if (taskIndex === -1) {
return conn.reply(m.chat, "Invalid task ID.", m);
}
taskData.task[taskIndex].status = validStatuses.find(status => status.toLowerCase() === newStatus);
fs.writeFileSync(taskFilePath, JSON.stringify(taskData, null, 2));
const updatedTask = taskData.task[taskIndex];
const message = `✅ *Task Updated Successfully!* ✅\n\n` + `🆔 *ID:* ${updatedTask.id}\n` + `📝 *Detail:* ${updatedTask.detail}\n` + `📅 *Due Date:* ${updatedTask.due}\n` + `👥 *Assigned to:* ${updatedTask.staff}\n` + `🔖 *New Status:* ${updatedTask.status}\n\n` + `Keep up the great work! 💪`;
await conn.reply(m.chat, message, m);
};
handler.command = /^(updatetask)$/i;
export default handler;