|
|
@ -2,6 +2,16 @@ import { sendMessage } from '../utils/messaging';
|
|
|
|
import { createTask, assignTask, completeTask, getPendingTasks } from '../../services/taskService';
|
|
|
|
import { createTask, assignTask, completeTask, getPendingTasks } from '../../services/taskService';
|
|
|
|
import { setRemindersEnabled } from '../../services/userService';
|
|
|
|
import { setRemindersEnabled } from '../../services/userService';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function formatTaskList(tasks: any[]) {
|
|
|
|
|
|
|
|
if (tasks.length === 0) {
|
|
|
|
|
|
|
|
return 'No tienes tareas pendientes.';
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return tasks.map((task) => {
|
|
|
|
|
|
|
|
return `- Tarea ${task.id}: ${task.description}${task.dueDate ? ` (para el ${task.dueDate})` : ''}`;
|
|
|
|
|
|
|
|
}).join('\n');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export function handleTaskCommand(body: string, sender: string, groupId: string, linkedGroups: Set<string>) {
|
|
|
|
export function handleTaskCommand(body: string, sender: string, groupId: string, linkedGroups: Set<string>) {
|
|
|
|
if (groupId && linkedGroups.has(groupId)) {
|
|
|
|
if (groupId && linkedGroups.has(groupId)) {
|
|
|
|
if (body.startsWith('/tarea')) {
|
|
|
|
if (body.startsWith('/tarea')) {
|
|
|
@ -27,7 +37,18 @@ export function handleTaskCommand(body: string, sender: string, groupId: string,
|
|
|
|
.replace(/\d{4}-\d{2}-\d{2}/g, '')
|
|
|
|
.replace(/\d{4}-\d{2}-\d{2}/g, '')
|
|
|
|
.trim();
|
|
|
|
.trim();
|
|
|
|
|
|
|
|
|
|
|
|
if (action === 'nueva') {
|
|
|
|
if (!action || action === 'mostrar') {
|
|
|
|
|
|
|
|
// Handle bare /tarea or /tarea mostrar
|
|
|
|
|
|
|
|
const user = `@${sender.split('@')[0]}`; // Default to the sender
|
|
|
|
|
|
|
|
const tasks = getPendingTasks(user);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (tasks.length === 0) {
|
|
|
|
|
|
|
|
sendMessage(sender, 'No tienes tareas pendientes.');
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
const taskList = formatTaskList(tasks);
|
|
|
|
|
|
|
|
sendMessage(sender, `Tus tareas pendientes:\n${taskList}`);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if (action === 'nueva') {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
const finalAssignedUser = assignedUser || `@${sender.split('@')[0]}`;
|
|
|
|
const finalAssignedUser = assignedUser || `@${sender.split('@')[0]}`;
|
|
|
|
const task = createTask(sender, {
|
|
|
|
const task = createTask(sender, {
|
|
|
|