Fix nullref exceptions from Rich Presences

This commit is contained in:
Christopher F
2018-01-05 20:49:59 -05:00
parent 227f61aa4e
commit c08f37bb03

View File

@@ -17,9 +17,9 @@
State = model.State.GetValueOrDefault(), State = model.State.GetValueOrDefault(),
SmallAsset = assets?[0], SmallAsset = assets?[0],
LargeAsset = assets?[1], LargeAsset = assets?[1],
Party = model.Party.GetValueOrDefault()?.ToEntity(), Party = model.Party.IsSpecified ? model.Party.Value.ToEntity() : null,
Secrets = model.Secrets.GetValueOrDefault()?.ToEntity(), Secrets = model.Secrets.IsSpecified ? model.Secrets.Value.ToEntity() : null,
Timestamps = model.Timestamps.GetValueOrDefault()?.ToEntity() Timestamps = model.Timestamps.IsSpecified ? model.Timestamps.Value.ToEntity() : null
}; };
} }
// Stream Game // Stream Game
@@ -56,11 +56,9 @@
public static GameParty ToEntity(this API.GameParty model) public static GameParty ToEntity(this API.GameParty model)
{ {
// todo: proper fix for this
if (model == null) return null;
// Discord will probably send bad data since they don't validate anything // Discord will probably send bad data since they don't validate anything
int current = 0, cap = 0; int current = 0, cap = 0;
if (model.Size.Length == 2) if (model.Size?.Length == 2)
{ {
current = model.Size[0]; current = model.Size[0];
cap = model.Size[1]; cap = model.Size[1];