0.2.2 Optimized Focus Task

This commit is contained in:
liyunze 2026-04-12 12:13:55 +10:00
parent b065cd2138
commit b2d7c74cf9
2 changed files with 12 additions and 9 deletions

19
Code.cs
View file

@ -377,6 +377,8 @@ public class TaskOperations
if (taskData[key].Tasks.Any(t => t.Name.Equals(taskName, StringComparison.OrdinalIgnoreCase) && !t.Completed))
return new Response<(int, string)>(false, default, $"❌ Error: Task '{taskName}' already exists");
if (focused)
Unfocus();
taskData[key].Username = getUsername();
taskData[key].Tasks.Add(new Task(taskName, completed, focused));
if (completed)
@ -453,18 +455,18 @@ public class TaskOperations
public void Unfocus()
{
var tasks = ListUserTasks();
UnfocusAll(tasks);
tasks = UnfocusAll(tasks);
SaveIntoTasks(tasks);
}
private void UnfocusAll(List<Task> tasks)
private List<Task> UnfocusAll(List<Task> tasks)
{
for (int i = 0; i < tasks.Count; i++)
tasks[i].Focused = false;
return tasks;
}
public void SaveIntoTasks(List<Task> tasks)
{
string key = getKey();
@ -534,7 +536,7 @@ public class CPHInline
SaveTasks();
}
#region Platform Helpers
#region Platform Helpers
private void Broadcast(object body, string key)
{
string json = JsonConvert.SerializeObject(new { source = "rython-task-bot", id = key ?? GetKey(), body = body, username = GetUsername() });
@ -629,8 +631,8 @@ public class CPHInline
}
}
#endregion
#region Commands
#endregion
#region Commands
public bool HelpCommand()
{
Respond("📝 Rython Task Bot Commands: !task !edit !remove !done. For mods, you can do !adel @user. More commmands here: https://github.com/liyunze-coding/rython-task-bot-v2#usage");
@ -1114,8 +1116,9 @@ public class CPHInline
{
Respond($"You have completed {completedCount} task(s) so far!");
}
return true;
}
#endregion
#endregion
}
#endregion

File diff suppressed because one or more lines are too long