refactor: don't DI IDatabase and ModelRepository into bot command classes
This commit is contained in:
@@ -4,17 +4,13 @@ namespace PluralKit.Bot;
|
||||
|
||||
public class Random
|
||||
{
|
||||
private readonly IDatabase _db;
|
||||
private readonly EmbedService _embeds;
|
||||
private readonly ModelRepository _repo;
|
||||
|
||||
private readonly global::System.Random randGen = new();
|
||||
|
||||
public Random(EmbedService embeds, IDatabase db, ModelRepository repo)
|
||||
public Random(EmbedService embeds)
|
||||
{
|
||||
_embeds = embeds;
|
||||
_db = db;
|
||||
_repo = repo;
|
||||
}
|
||||
|
||||
// todo: get postgresql to return one random member/group instead of querying all members/groups
|
||||
@@ -23,7 +19,7 @@ public class Random
|
||||
{
|
||||
ctx.CheckSystem();
|
||||
|
||||
var members = await _repo.GetSystemMembers(ctx.System.Id).ToListAsync();
|
||||
var members = await ctx.Repository.GetSystemMembers(ctx.System.Id).ToListAsync();
|
||||
|
||||
if (!ctx.MatchFlag("all", "a"))
|
||||
members = members.Where(m => m.MemberVisibility == PrivacyLevel.Public).ToList();
|
||||
@@ -41,7 +37,7 @@ public class Random
|
||||
{
|
||||
ctx.CheckSystem();
|
||||
|
||||
var groups = await _repo.GetSystemGroups(ctx.System.Id).ToListAsync();
|
||||
var groups = await ctx.Repository.GetSystemGroups(ctx.System.Id).ToListAsync();
|
||||
if (!ctx.MatchFlag("all", "a"))
|
||||
groups = groups.Where(g => g.Visibility == PrivacyLevel.Public).ToList();
|
||||
|
||||
@@ -60,8 +56,7 @@ public class Random
|
||||
var opts = ctx.ParseListOptions(ctx.DirectLookupContextFor(group.System));
|
||||
opts.GroupFilter = group.Id;
|
||||
|
||||
await using var conn = await _db.Obtain();
|
||||
var members = await conn.QueryMemberList(ctx.System.Id, opts.ToQueryOptions());
|
||||
var members = await ctx.Database.Execute(conn => conn.QueryMemberList(ctx.System.Id, opts.ToQueryOptions()));
|
||||
|
||||
if (members == null || !members.Any())
|
||||
throw new PKError(
|
||||
|
||||
Reference in New Issue
Block a user