Skip to content

Commit

Permalink
Fix NRE on startup when custom status messages are set but presence i…
Browse files Browse the repository at this point in the history
…s null
  • Loading branch information
FloatingMilkshake committed Oct 21, 2024
1 parent 83a0479 commit ce25748
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions Tasks/ActivityTasks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ await Program.Db.HashSetAsync("customStatus", "userStatus",
}

var chosenStatus = random.Next(0, customStatusList.Length);
if (!string.IsNullOrWhiteSpace(Program.Discord.CurrentUser.Presence.Activity.Name))
// ReSharper disable once ConditionIsAlwaysTrueOrFalse
if (Program.Discord.CurrentUser.Presence is not null && !string.IsNullOrWhiteSpace(Program.Discord.CurrentUser.Presence.Activity.Name))
if (customStatusList.Length != 1)
while (customStatusList[chosenStatus].Name.ToString() ==
Program.Discord.CurrentUser.Presence.Activity.Name)
Expand Down Expand Up @@ -150,7 +151,8 @@ await Program.Db.HashSetAsync("customStatus", "userStatus",
return;
}

if (string.IsNullOrWhiteSpace(Program.Discord.CurrentUser.Presence.Activity.Name))
// ReSharper disable once ConditionIsAlwaysTrueOrFalse
if (Program.Discord.CurrentUser.Presence is null || string.IsNullOrWhiteSpace(Program.Discord.CurrentUser.Presence.Activity.Name))
await Program.Db.StringSetAsync("customStatusLastUpdated", $"{DateTime.Now}");
else
await Program.Db.StringSetAsync("customStatusLastUpdated",
Expand Down

0 comments on commit ce25748

Please sign in to comment.