Added .todo show, Renamed ReactionRole* commands to rero*

This commit is contained in:
Kwoth
2024-05-02 23:23:26 +00:00
parent 3ef05f8aa7
commit 48e51784da
10 changed files with 83 additions and 34 deletions

View File

@@ -66,6 +66,22 @@ public partial class Utility
.SendAsync();
}
[Cmd]
public async Task TodoShow(kwum todoId)
{
var todo = await _service.GetTodoAsync(ctx.User.Id, todoId);
if (todo is null)
{
await Response().Error(strs.todo_not_found).SendAsync();
return;
}
await Response()
.Confirm($"`{new kwum(todo.Id)}` {todo.Todo}")
.SendAsync();
}
[Cmd]
public async Task TodoComplete(kwum todoId)
@@ -105,7 +121,7 @@ public partial class Utility
var sb = new StringBuilder();
foreach (var todo in todos)
{
sb.AppendLine($"{(todo.IsDone ? "" : "")} {Format.Code(new kwum(todo.Id).ToString())} {todo.Todo}");
sb.AppendLine(InternalItemShow(todo));
sb.AppendLine("---");
}
@@ -113,6 +129,9 @@ public partial class Utility
eb.WithDescription(sb.ToString());
}
private static string InternalItemShow(TodoModel todo)
=> $"{(todo.IsDone ? "" : "")} {Format.Code(new kwum(todo.Id).ToString())} {todo.Todo}";
[Group("archive")]
public partial class ArchiveCommands : NadekoModule<TodoService>
{

View File

@@ -179,4 +179,14 @@ public sealed class TodoService
return count > 0;
}
public async Task<TodoModel?> GetTodoAsync(ulong userId, int todoId)
{
await using var ctx = _db.GetDbContext();
return await ctx
.GetTable<TodoModel>()
.Where(x => x.UserId == userId && x.Id == todoId)
.FirstOrDefaultAsyncLinqToDB();
}
}

View File

@@ -664,11 +664,17 @@ public partial class Utility : NadekoModule
.WithReferences(this.GetType().Assembly)
.WithImports(
"System",
"System.Collections.Generic",
"System.IO",
"System.Linq",
"System.Net.Http",
"System.Threading",
"System.Threading.Tasks",
"NadekoBot",
"NadekoBot.Extensions",
"Microsoft.Extensions.DependencyInjection",
"NadekoBot.Common",
"NadekoBot.Modules",
"System.Text",
"System.Text.Json"),
globalsType: typeof(EvalGlobals));