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

@@ -133,14 +133,29 @@ public class Context
await Reply($"{Emojis.Warn} This command is deprecated and will be removed soon. In the future, please use `pk;{commandDef.Key}`.");
}
public LookupContext LookupContextFor(PKSystem target) =>
System?.Id == target.Id ? LookupContext.ByOwner : LookupContext.ByNonOwner;
public LookupContext LookupContextFor(SystemId systemId)
{
var hasPrivateOverride = this.MatchFlag("private", "priv");
var hasPublicOverride = this.MatchFlag("public", "pub");
public LookupContext LookupContextFor(SystemId systemId) =>
System?.Id == systemId ? LookupContext.ByOwner : LookupContext.ByNonOwner;
if (hasPrivateOverride && hasPublicOverride)
throw new PKError("Cannot match both public and private flags at the same time.");
public LookupContext LookupContextFor(PKMember target) =>
System?.Id == target.System ? LookupContext.ByOwner : LookupContext.ByNonOwner;
if (System.Id != systemId)
{
if (hasPrivateOverride)
throw Errors.NotOwnInfo;
return LookupContext.ByNonOwner;
}
if (hasPrivateOverride)
return LookupContext.ByOwner;
if (hasPublicOverride)
return LookupContext.ByNonOwner;
// todo: add config defaults
return LookupContext.ByOwner;
}
public IComponentContext Services => _provider;
}