private void SubscribeToTeleSubscriptionUpdates( string s, WebSocketIncomingMessage im, bool subscribing ) { if (!(im.Data is long id)) { return; } var sub = Bot.Subscriptions.FirstOrDefault(x => x.Id == id); if (sub is null) { Send(WebSocketMessageBuilder.Error($"{id} not found is subscriptions.")); return; } if (subscribing) { sub.Updated += SubOnUpdated; } else { sub.Updated -= SubOnUpdated; } }
protected virtual void HandleCommand(WebSocketIncomingMessage im) { if (AvailableCommands.Keys.Any(x => x == im)) { var kp = AvailableCommands.First(x => x.Key == im); kp.Value?.Invoke(kp.Key, im); } else { Send(WebSocketMessageBuilder.Error($"{im.Name} not a valid command.")); } }
protected virtual void HandleUnsubscribe(WebSocketIncomingMessage im) { if (AvailableSubscriptions.Keys.Any(x => x == im) && Subscriptions.Remove(im)) { var kp = AvailableSubscriptions.First(x => x.Key == im); kp.Value?.Invoke(kp.Key, im, false); Send(WebSocketMessageBuilder.Unsubscribe(kp.Key)); } else { Send(WebSocketMessageBuilder.Error($"{im.Name} doesn't exist or not subscribed.")); } }