feat: public/private lookup flags, consistency

This commit is contained in:
spiral
2021-12-06 00:32:54 -05:00
parent aacf5909a9
commit 455830a2b5
16 changed files with 44 additions and 40 deletions

View File

@@ -599,7 +599,7 @@ public class Groups
var frontpercent = await _db.Execute(c =>
_repo.GetFrontBreakdown(c, targetSystem.Id, target.Id, rangeStart.Value.ToInstant(), now));
await ctx.Reply(embed: await _embeds.CreateFrontPercentEmbed(frontpercent, targetSystem, target,
ctx.Zone, ctx.LookupContextFor(targetSystem), title.ToString(), ignoreNoFronters, showFlat));
ctx.Zone, ctx.LookupContextFor(targetSystem.Id), title.ToString(), ignoreNoFronters, showFlat));
}
private async Task<PKSystem> GetGroupSystem(Context ctx, PKGroup target)

View File

@@ -60,7 +60,7 @@ public static class ContextListExt
// PERM CHECK: If we're trying to access non-public members of another system, error
if (p.PrivacyFilter != PrivacyLevel.Public && lookupCtx != LookupContext.ByOwner)
// TODO: should this just return null instead of throwing or something? >.>
throw new PKError("You cannot look up private members of another system.");
throw Errors.NotOwnInfo;
// Additional fields to include in the search results
if (ctx.MatchFlag("with-last-switch", "with-last-fronted", "with-last-front", "wls", "wlf"))

View File

@@ -120,14 +120,14 @@ public class Member
{
var system = await _repo.GetSystem(target.System);
await ctx.Reply(
embed: await _embeds.CreateMemberEmbed(system, target, ctx.Guild, ctx.LookupContextFor(system), ctx.Zone));
embed: await _embeds.CreateMemberEmbed(system, target, ctx.Guild, ctx.LookupContextFor(system.Id), ctx.Zone));
}
public async Task Soulscream(Context ctx, PKMember target)
{
// this is for a meme, please don't take this code seriously. :)
var name = target.NameFor(ctx.LookupContextFor(target));
var name = target.NameFor(ctx.LookupContextFor(target.System));
var encoded = HttpUtility.UrlEncode(name);
var resp = await _client.GetAsync($"https://onomancer.sibr.dev/api/generateStats2?name={encoded}");

View File

@@ -43,7 +43,7 @@ public class MemberAvatar
{
var currentValue = location == AvatarLocation.Member ? target.AvatarUrl : guildData?.AvatarUrl;
var canAccess = location != AvatarLocation.Member ||
target.AvatarPrivacy.CanAccess(ctx.LookupContextFor(target));
target.AvatarPrivacy.CanAccess(ctx.LookupContextFor(target.System));
if (string.IsNullOrEmpty(currentValue) || !canAccess)
{
if (location == AvatarLocation.Member)

View File

@@ -329,7 +329,7 @@ public class MemberEdit
private async Task<EmbedBuilder> CreateMemberNameInfoEmbed(Context ctx, PKMember target)
{
var lcx = ctx.LookupContextFor(target);
var lcx = ctx.LookupContextFor(target.System);
MemberGuildSettings memberGuildConfig = null;
if (ctx.Guild != null)

View File

@@ -34,7 +34,7 @@ public class Random
var randInt = randGen.Next(members.Count);
await ctx.Reply(embed: await _embeds.CreateMemberEmbed(ctx.System, members[randInt], ctx.Guild,
ctx.LookupContextFor(ctx.System), ctx.Zone));
ctx.LookupContextFor(ctx.System.Id), ctx.Zone));
}
public async Task Group(Context ctx)
@@ -72,6 +72,6 @@ public class Random
var randInt = randGen.Next(ms.Count);
await ctx.Reply(embed: await _embeds.CreateMemberEmbed(ctx.System, ms[randInt], ctx.Guild,
ctx.LookupContextFor(ctx.System), ctx.Zone));
ctx.LookupContextFor(ctx.System.Id), ctx.Zone));
}
}

View File

@@ -50,7 +50,7 @@ public class Switch
// Make sure the requested switch isn't identical to the last one
if (await lastSwitchMembers.Select(m => m.Id)
.SequenceEqualAsync(members.Select(m => m.Id).ToAsyncEnumerable()))
throw Errors.SameSwitch(members, ctx.LookupContextFor(ctx.System));
throw Errors.SameSwitch(members, ctx.LookupContextFor(ctx.System.Id));
}
await _repo.AddSwitch(conn, ctx.System.Id, members.Select(m => m.Id).ToList());
@@ -138,7 +138,7 @@ public class Switch
// Make sure switch isn't being edited to have the members it already does
if (await lastSwitchMembers.Select(m => m.Id)
.SequenceEqualAsync(members.Select(m => m.Id).ToAsyncEnumerable()))
throw Errors.SameSwitch(members, ctx.LookupContextFor(ctx.System));
throw Errors.SameSwitch(members, ctx.LookupContextFor(ctx.System.Id));
// Send a prompt asking the user to confirm the switch
var lastSwitchDeltaStr = (SystemClock.Instance.GetCurrentInstant() - lastSwitch.Timestamp).FormatDuration();

View File

@@ -17,7 +17,7 @@ public class System
{
if (system == null) throw Errors.NoSystemError;
await ctx.Reply(embed: await _embeds.CreateSystemEmbed(ctx, system, ctx.LookupContextFor(system)));
await ctx.Reply(embed: await _embeds.CreateSystemEmbed(ctx, system, ctx.LookupContextFor(system.Id)));
}
public async Task New(Context ctx)

View File

@@ -27,7 +27,7 @@ public class SystemFront
var sw = await _repo.GetLatestSwitch(system.Id);
if (sw == null) throw Errors.NoRegisteredSwitches;
await ctx.Reply(embed: await _embeds.CreateFronterEmbed(sw, ctx.Zone, ctx.LookupContextFor(system)));
await ctx.Reply(embed: await _embeds.CreateFronterEmbed(sw, ctx.Zone, ctx.LookupContextFor(system.Id)));
}
public async Task SystemFrontHistory(Context ctx, PKSystem system)
@@ -128,7 +128,7 @@ public class SystemFront
var frontpercent = await _db.Execute(c =>
_repo.GetFrontBreakdown(c, system.Id, null, rangeStart.Value.ToInstant(), now));
await ctx.Reply(embed: await _embeds.CreateFrontPercentEmbed(frontpercent, system, null, ctx.Zone,
ctx.LookupContextFor(system), title.ToString(), ignoreNoFronters, showFlat));
ctx.LookupContextFor(system.Id), title.ToString(), ignoreNoFronters, showFlat));
}
private struct FrontHistoryEntry

View File

@@ -11,9 +11,9 @@ public class SystemList
if (target == null) throw Errors.NoSystemError;
ctx.CheckSystemPrivacy(target, target.MemberListPrivacy);
var opts = ctx.ParseMemberListOptions(ctx.LookupContextFor(target));
var opts = ctx.ParseMemberListOptions(ctx.LookupContextFor(target.Id));
await ctx.RenderMemberList(
ctx.LookupContextFor(target),
ctx.LookupContextFor(target.Id),
target.Id,
GetEmbedTitle(target, opts),
target.Color,