Beispiel #1
0
 private void SetupOBS()
 {
     _notifierMediatorService.Notify("OBS is being setup");
     OBSClient.Connected    += OnObsConnected;
     OBSClient.Disconnected += OnObsDisconnected;
     ConnectOBS();
 }
        public async Task <string> Get()
        {
            await _publishEndpoint.Publish <Message>(new { Text = "gateway" });

            _notifierMediatorService.Notify("gateway");
            return("gateway");
        }
        public async Task <IActionResult> Get()
        {
            var query  = new GetTemperaturesQuery();
            var result = await _mediator.Send(query);

            _notifierMediatorService.Notify("Calling Gettemperature Endpoint. ");
            return(Ok(result));
        }
Beispiel #4
0
 private void SetupOBS()
 {
     OBSClient = _services.GetRequiredService <OBSWebsocket>();
     _notifierMediatorService.Notify("OBS is being setup");
     OBSClient.Connected    += OnObsConnected;
     OBSClient.Disconnected += OnObsDisconnected;
     ConnectOBS();
     OnReady?.Invoke(this, EventArgs.Empty);
 }
Beispiel #5
0
        public async Task Handle(ChatNotification notification, CancellationToken cancellationToken)
        {
            if (
                notification.ChatMessage.Message.Trim().StartsWith("!") ||
                _config.IgnoredUsers.Any(iu => iu.Equals(notification.ChatMessage.Username, StringComparison.InvariantCultureIgnoreCase))
                )
            {
                return;
            }

            var sanitizedHtml = System.Net.WebUtility.HtmlDecode(_sanitizer.Sanitize(notification.ChatMessage.Message));
            var emotes        = _mapper.Map <IEnumerable <EmoteDto> >(notification.ChatMessage.EmoteSet.Emotes);

            var userTypes = UserTypes.None;

            if (notification.ChatMessage.IsBroadcaster)
            {
                userTypes |= UserTypes.Broadcaster;
            }
            if (notification.ChatMessage.IsModerator)
            {
                userTypes |= UserTypes.Moderator;
            }
            if (notification.ChatMessage.IsSubscriber)
            {
                userTypes |= UserTypes.Subscriber;
            }
            if (notification.ChatMessage.IsVip)
            {
                userTypes |= UserTypes.Vip;
            }
            if (_config.TeamMembers.Any(tm =>
                                        tm.Id.Equals(notification.ChatMessage.UserId, StringComparison.InvariantCultureIgnoreCase)))
            {
                userTypes |= UserTypes.TeamMember;
            }

            var data = new ChatMessageData
            {
                MessageId           = notification.ChatMessage.Id,
                UserId              = notification.ChatMessage.UserId,
                UserName            = notification.ChatMessage.Username,
                DisplayName         = notification.ChatMessage.DisplayName,
                Message             = sanitizedHtml,
                TeamName            = _config.TeamName,
                TeamShoutoutEnabled = _config.TeamShoutoutEnabled,
                EmoteDetails        = emotes.ToArray(),
                UserTypes           = userTypes
            };

            var bcn = new BasicChatNotification(data);
            await Task.Run(() => _notifierMediatorService.Notify(bcn), cancellationToken);

            // _notifierMediatorService.Notify(bcn);
            // await _twitchHub.Clients.All.SendAsync("ReceiveChatMessage", data, uo, cancellationToken: cancellationToken);
        }
        public Task Handle(ChatNotification notification, CancellationToken cancellationToken)
        {
            if (
                notification.ChatMessage.Message.Trim().StartsWith("!") ||
                _config.IgnoredUsers.Any(iu => iu.Equals(notification.ChatMessage.Username, StringComparison.InvariantCultureIgnoreCase))
                )
            {
                return(Task.CompletedTask);
            }

            _notifierMediatorService.Notify(new CallOutCommand(notification.ChatMessage.UserId, notification.ChatMessage.Username));
            return(Task.CompletedTask);
        }
 public ActionResult <string> NotifyAll()
 {
     _notifierMediatorService.Notify("This is a test notification");
     return("Completed");
 }
        public ContentResult NotifyAllContentResult()
        {
            _notifierMediatorService.Notify();

            return(Content("NotifyAllContentResult"));
        }
        public async Task Handle(DadJokeCommand notification, CancellationToken cancellationToken)
        {
            try
            {
                var dadJoke = await _service.GetDadJoke();

                if (dadJoke == null)
                {
                    return;
                }
                var uo = _twitchApiClient.Helix.Users.GetUsersAsync(logins: new List <string> {
                    notification.ChatCommand.ChatMessage.DisplayName
                }).Result.Users.FirstOrDefault();
                if (uo == null)
                {
                    return;
                }

                var message = $"@{uo.DisplayName} Here's your dad joke: \"{dadJoke.Joke}\"";
                _twitchClient.SendMessage(_config.Chat.Channel, message);
                return;

                var emotes = _mapper.Map <IEnumerable <EmoteDto> >(notification.ChatCommand.ChatMessage.EmoteSet.Emotes);

                var userTypes = UserTypes.None;
                if (notification.ChatCommand.ChatMessage.IsBroadcaster)
                {
                    userTypes |= UserTypes.Broadcaster;
                }
                if (notification.ChatCommand.ChatMessage.IsModerator)
                {
                    userTypes |= UserTypes.Moderator;
                }
                if (notification.ChatCommand.ChatMessage.IsSubscriber)
                {
                    userTypes |= UserTypes.Subscriber;
                }
                if (notification.ChatCommand.ChatMessage.IsVip)
                {
                    userTypes |= UserTypes.Vip;
                }
                if (_config.TeamMembers.Any(tm =>
                                            tm.Id.Equals(notification.ChatCommand.ChatMessage.UserId, StringComparison.InvariantCultureIgnoreCase)))
                {
                    userTypes |= UserTypes.TeamMember;
                }

                var data = new ChatMessageData
                {
                    MessageId           = notification.ChatCommand.ChatMessage.Id,
                    UserId              = notification.ChatCommand.ChatMessage.UserId,
                    UserName            = notification.ChatCommand.ChatMessage.Username,
                    DisplayName         = notification.ChatCommand.ChatMessage.DisplayName,
                    Message             = dadJoke.Joke,
                    TeamName            = _config.TeamName,
                    TeamShoutoutEnabled = _config.TeamShoutoutEnabled,
                    EmoteDetails        = emotes.ToArray(),
                    UserTypes           = userTypes
                };

                _notifierMediatorService.Notify(new BasicChatNotification(data, uo));
                // await _twitchHub.Clients.All.SendAsync("ReceiveMessage", notification.ChatCommand.ChatMessage.DisplayName, "dadjoke", uo, cancellationToken: cancellationToken);
            }
            catch
            {
                // do nothing
            }
        }
Beispiel #10
0
        public async Task ReceiveAsync(string[] topics, CancellationToken stoppingToken, bool forever = true)
        {
            /* _consumer.Subscribe(topics);
             * foreach (var topic in topics)
             * {
             *   Console.WriteLine($"**KafkaClient::ReceiveAsync - consuming on topic {topic}");
             * }
             *
             * do
             * {
             *   if (stoppingToken.IsCancellationRequested)
             *   {
             *       forever = false;
             *   }
             *
             *   var data = _consumer.Consume();
             *   Console.WriteLine($"**KafkaClient::ReceiveAsync - key : {data.Message.Key}");
             *
             *   Console.WriteLine($"**KafkaClient::ReceiveAsync - partition : {data.Partition.Value}");
             *   Console.WriteLine($"**KafkaClient::ReceiveAsync - offset : {data.Offset.Value}");
             *   var message = new NotificationMessage<string> { Message = data.Message.Value };
             *   Console.WriteLine($"**KafkaClient::ReceiveAsync - message : {message.Message}");
             *   await _notifierMediatorService.Notify(message);
             * } while (forever);*/

            try
            {
                _consumer.Subscribe(topics);
                Console.WriteLine($"**KafkaClient::ReceiveAsync - consuming on topic {string.Join(' ', topics)}");
                while (true)
                {
                    var data = _consumer.Consume();

                    if (data?.Message?.Value == null)
                    {
                        continue;
                    }

                    Console.WriteLine($"**KafkaClient::ReceiveAsync - key : {data.Message.Key}");

                    Console.WriteLine($"**KafkaClient::ReceiveAsync - partition : {data.Partition.Value}");
                    Console.WriteLine($"**KafkaClient::ReceiveAsync - offset : {data.Offset.Value}");
                    var message = new NotificationMessage <string> {
                        Message = data.Message.Value
                    };
                    Console.WriteLine($"**KafkaClient::ReceiveAsync - message : {message.Message}");
                    await _notifierMediatorService.Notify(message);

                    _consumer.Commit(data);
                    _consumer.StoreOffset(data);
                    Thread.Sleep(TimeSpan.FromSeconds(5));
                }
            }
            catch (KafkaException e)
            {
                Console.WriteLine($"Consume error: {e.Message}");
                Console.WriteLine("Exiting producer...");
            }
            finally
            {
                _consumer.Close();
            }
        }
 public ActionResult <string> NotifyAll()
 {
     _notifierMediatorService.Notify($"This is a test notification from {nameof(StudenController)}.NotifyAll()");
     return("Completed");
 }
Beispiel #12
0
 private void ClientOnMessageReceived(object sender, OnMessageReceivedArgs e)
 {
     _notifierMediatorService.Notify(new ChatNotification(e.ChatMessage));
 }
Beispiel #13
0
 public ActionResult <string> NotifyAll()
 {
     _notifierMediatorService.Notify();
     return("Completed");
 }