Bug fixes, focused and completed command

This commit is contained in:
liyunze 2026-02-25 00:56:54 +11:00
parent 765b240104
commit 12b44e413e
2 changed files with 77 additions and 11 deletions

86
Code.cs
View file

@ -12,7 +12,6 @@
// - No Warranty: The software is provided "as-is," without warranty of any kind. // - No Warranty: The software is provided "as-is," without warranty of any kind.
// //
// For more details, see https://www.gnu.org/licenses/gpl-3.0.en.html. // For more details, see https://www.gnu.org/licenses/gpl-3.0.en.html.
using Streamer.bot.Plugin.Interface; using Streamer.bot.Plugin.Interface;
using Streamer.bot.Plugin.Interface.Model; using Streamer.bot.Plugin.Interface.Model;
using Streamer.bot.Plugin.Interface.Enums; using Streamer.bot.Plugin.Interface.Enums;
@ -29,7 +28,6 @@ using Newtonsoft.Json.Linq;
/* /*
Todo Todo
delete based on days
{ {
platform-userId: { platform-userId: {
@ -84,10 +82,10 @@ public class Response
public bool Success { get; set; } public bool Success { get; set; }
public string ErrorMsg { get; set; } public string ErrorMsg { get; set; }
public Response(bool success, string errorMsg = null) public Response(bool Success, string ErrorMsg = null)
{ {
this.Success = success; this.Success = Success;
this.ErrorMsg = errorMsg; this.ErrorMsg = ErrorMsg;
} }
} }
@ -483,12 +481,29 @@ public class CPHInline
} }
else else
{ {
Respond($"Current focused task: {AddOrSelectResponse.Data.Item1}. {AddOrSelectResponse.Data.Item2}"); Respond($"Current focused task: {AddOrSelectResponse.Data.Item1 + 1}. {AddOrSelectResponse.Data.Item2}");
} }
return true; return true;
} }
// FOCUSED COMMAND
// Returns only the focused task
public bool FocusedCommand()
{
List<Task> userTasks = ListUserTasks();
int focusedTaskIndex = GetFocusedTask();
if (focusedTaskIndex == -1)
{
Respond("You do not have a focused task.");
return true;
}
var focusedTask = userTasks[focusedTaskIndex];
Respond($"Current focused task: {focusedTaskIndex + 1}. {focusedTask.Name}");
return true;
}
// return true index // return true index
private int GetFocusedTask() private int GetFocusedTask()
{ {
@ -544,6 +559,7 @@ public class CPHInline
if (!EditData.Success) if (!EditData.Success)
{ {
Respond(EditData.ErrorMsg); Respond(EditData.ErrorMsg);
return false;
} }
int taskIndex = EditData.Data.Item1; int taskIndex = EditData.Data.Item1;
@ -568,7 +584,6 @@ public class CPHInline
// task data doesn't exist // task data doesn't exist
if (userTasks.Count == 0) if (userTasks.Count == 0)
{ {
// Respond("404 Tasks not found");
return new(false, default, "Error 404: Tasks not found"); return new(false, default, "Error 404: Tasks not found");
} }
@ -643,8 +658,7 @@ public class CPHInline
// user's data doesn't exist // user's data doesn't exist
string key = userKey ?? GetKey(); string key = userKey ?? GetKey();
var userData = this.taskData[key]; if (!this.taskData.TryGetValue(key, out var userData))
if (userData == null)
{ {
return emptyList; return emptyList;
} }
@ -689,12 +703,64 @@ public class CPHInline
// JOIN THE TASKS INTO ONE MESSAGE // JOIN THE TASKS INTO ONE MESSAGE
// edit however you like // edit however you like
string message = String.Join(" | ", userTasks.Select((t, index) => $"{index + 1}. {(t.Focused ? "(ongoing) " : "")}{t.Name}")); var IncompleteTasks = userTasks.Select((t, index) => new { t, index }).Where(x => !x.t.Completed);
string message = String.Join(" | ", IncompleteTasks.Select(x => $"{x.index + 1}. {(x.t.Focused ? "(ongoing) " : "")}{x.t.Name}"));
if (someoneElse) if (someoneElse)
{ {
string theirUser = GetUsername(key); string theirUser = GetUsername(key);
message = $"{theirUser}'s tasks: {message}"; message = $"{theirUser}'s tasks: {message}";
} }
else
{
message = $"{IncompleteTasks.Count()} tasks pending: {message}";
}
Respond(message);
return true;
}
public bool CompletedCommand()
{
CPH.TryGetArg("rawInput", out string rawInput);
rawInput = rawInput.Trim();
string? key = null;
bool someoneElse = false;
if (!String.IsNullOrWhiteSpace(rawInput))
{
key = GetKey(rawInput);
if (key == "")
{
Respond("User not found");
return false;
}
else
{
someoneElse = true;
}
}
List<Task> userTasks = ListUserTasks(key);
// task data doesn't exist
if (userTasks.Count == 0)
{
Respond("404 Tasks not found");
return false;
}
// JOIN THE TASKS INTO ONE MESSAGE
// edit however you like
var CompletedTasks = userTasks.Select((t, index) => new { t, index }).Where(x => x.t.Completed);
string message = String.Join(" | ", CompletedTasks.Select(x => $"{x.index + 1}. {x.t.Name}"));
if (someoneElse)
{
string theirUser = GetUsername(key);
message = $"{theirUser}'s tasks: {message}";
}
else
{
message = $"Completed {CompletedTasks.Count()} tasks: {message}";
}
Respond(message); Respond(message);
return true; return true;
} }

File diff suppressed because one or more lines are too long