mirror of
https://github.com/liyunze-coding/rython-task-bot-v2.git
synced 2026-09-22 07:24:27 +00:00
0.2.2 Optimized Focus Task
This commit is contained in:
parent
b065cd2138
commit
b2d7c74cf9
2 changed files with 12 additions and 9 deletions
19
Code.cs
19
Code.cs
|
|
@ -377,6 +377,8 @@ public class TaskOperations
|
||||||
|
|
||||||
if (taskData[key].Tasks.Any(t => t.Name.Equals(taskName, StringComparison.OrdinalIgnoreCase) && !t.Completed))
|
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");
|
return new Response<(int, string)>(false, default, $"❌ Error: Task '{taskName}' already exists");
|
||||||
|
if (focused)
|
||||||
|
Unfocus();
|
||||||
taskData[key].Username = getUsername();
|
taskData[key].Username = getUsername();
|
||||||
taskData[key].Tasks.Add(new Task(taskName, completed, focused));
|
taskData[key].Tasks.Add(new Task(taskName, completed, focused));
|
||||||
if (completed)
|
if (completed)
|
||||||
|
|
@ -453,18 +455,18 @@ public class TaskOperations
|
||||||
public void Unfocus()
|
public void Unfocus()
|
||||||
{
|
{
|
||||||
var tasks = ListUserTasks();
|
var tasks = ListUserTasks();
|
||||||
UnfocusAll(tasks);
|
tasks = UnfocusAll(tasks);
|
||||||
SaveIntoTasks(tasks);
|
SaveIntoTasks(tasks);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UnfocusAll(List<Task> tasks)
|
private List<Task> UnfocusAll(List<Task> tasks)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < tasks.Count; i++)
|
for (int i = 0; i < tasks.Count; i++)
|
||||||
tasks[i].Focused = false;
|
tasks[i].Focused = false;
|
||||||
|
|
||||||
|
return tasks;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public void SaveIntoTasks(List<Task> tasks)
|
public void SaveIntoTasks(List<Task> tasks)
|
||||||
{
|
{
|
||||||
string key = getKey();
|
string key = getKey();
|
||||||
|
|
@ -534,7 +536,7 @@ public class CPHInline
|
||||||
SaveTasks();
|
SaveTasks();
|
||||||
}
|
}
|
||||||
|
|
||||||
#region Platform Helpers
|
#region Platform Helpers
|
||||||
private void Broadcast(object body, string key)
|
private void Broadcast(object body, string key)
|
||||||
{
|
{
|
||||||
string json = JsonConvert.SerializeObject(new { source = "rython-task-bot", id = key ?? GetKey(), body = body, username = GetUsername() });
|
string json = JsonConvert.SerializeObject(new { source = "rython-task-bot", id = key ?? GetKey(), body = body, username = GetUsername() });
|
||||||
|
|
@ -629,8 +631,8 @@ public class CPHInline
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
#region Commands
|
#region Commands
|
||||||
public bool HelpCommand()
|
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");
|
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!");
|
Respond($"You have completed {completedCount} task(s) so far!");
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
Loading…
Reference in a new issue