private async Task UpdateChannelAsync(IServerEmbedInfo embedInfo) { if (channel is null) { return; } using (await mutex.LockAsync( )) { var now = DateTime.Now; if (nextMessageWaitTime > now) { await Task.Delay(nextMessageWaitTime - now); } nextMessageWaitTime = now + Config.MessageCooldown; var port = embedInfo.Port; if (messages.TryGetValue(port, out var message)) { await message.TryModifyAsync(properties => { properties.Embed = embedInfo.Embed; }); } else { message = await channel.TrySendMessageAsync(embed : embedInfo.Embed); messages = messages.SetItem(port, message); } } }
private async Task NotifyUsersAsync(IServerEmbedInfo embedInfo) { if (embedInfo.EventType != ServerEventType.Offline) { return; } using (await mutex.LockAsync( )) { foreach (var user in users.Values) { await user.SendMessageAsync(embed : embedInfo.Embed); } } }
private void UpdateChannel(IServerEmbedInfo embedInfo) => Task.Run(() => UpdateChannelAsync(embedInfo));
private void NotifyUsers(IServerEmbedInfo embedInfo) => Task.Run(() => NotifyUsersAsync(embedInfo));