Skip to content

Commit

Permalink
add lock to callback
Browse files Browse the repository at this point in the history
  • Loading branch information
loukylor committed Nov 9, 2024
1 parent 40eda0e commit 0370b5e
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions TrickfireCheckIn/Discord/Bot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,23 +55,27 @@ public Bot(string token)
Client = builder.Build();

// Subscribe to updates of member list
object lock_ = new();
State.Members.CollectionChanged += (_, ev) =>
{
_needToUpdateEmbed = true;
lock(lock_)
{
_needToUpdateEmbed = true;

IEnumerable<string> oldItems = (ev.OldItems ?? new List<string>())
.Cast<(DiscordMember, DateTimeOffset)>()
.Select(val => val.Item1.DisplayName);
IEnumerable<string> oldItems = (ev.OldItems ?? new List<string>())
.Cast<(DiscordMember, DateTimeOffset)>()
.Select(val => val.Item1.DisplayName);

IEnumerable<string> newItems = (ev.NewItems ?? new List<string>())
.Cast<(DiscordMember, DateTimeOffset)>()
.Select(val => val.Item1.DisplayName);
IEnumerable<string> newItems = (ev.NewItems ?? new List<string>())
.Cast<(DiscordMember, DateTimeOffset)>()
.Select(val => val.Item1.DisplayName);

Client.Logger.LogInformation(
"Member collection changed: {}\nOld items: {}\nNew items: {}",
ev.Action.ToString(),
string.Join(", ", oldItems),
string.Join(", ", newItems));
Client.Logger.LogInformation(
"Member collection changed: {}\nOld items: {}\nNew items: {}",
ev.Action.ToString(),
string.Join(", ", oldItems),
string.Join(", ", newItems));
}
};
}

Expand Down

0 comments on commit 0370b5e

Please sign in to comment.