예제 #1
0
        private void Client_OnMessageReceived(object sender, TwitchLib.Client.Events.OnMessageReceivedArgs e)
        {
            string botCommandResponse = _chatMessageService.HandleBotCommands(e.ChatMessage.Message.Trim());

            if (string.IsNullOrEmpty(botCommandResponse))  // do something with luis
            {
                // Run async method in this sync method  (read https://cpratt.co/async-tips-tricks/)
                IntentResponse intentResponse = AsyncHelper.RunSync(() => _luisService.GetIntentAsync(e.ChatMessage.Message.Trim()));

                decimal certaintyThreshold;

                if (!decimal.TryParse(_luisConfiguration.LuisChatCertaintyThreshold, out certaintyThreshold))
                {
                    throw new ArgumentException(nameof(_luisConfiguration.LuisChatCertaintyThreshold));
                }


                if (intentResponse.Certainty > certaintyThreshold)
                {
                    string luisMappedResponse = _chatMessageService.MapLuisIntentToResponse(intentResponse);
                    _twitchClient.SendMessage(_twitchConfiguration.ChannelName, luisMappedResponse);
                }

                AddTwitchUserChatRecordToDb(e, intentResponse);
            }
            else // do something with explicit bot commands
            {
                _twitchClient.SendMessage(_twitchConfiguration.ChannelName, botCommandResponse);
            }
        }
        private void Client_OnMessageReceived(object sender, TwitchLib.Client.Events.OnMessageReceivedArgs e)
        {
            string botMessageResponse = _chatMessageService.HandleBotCommands(e);

            IntentResponse intentResponse = new IntentResponse {
                Certainty = null, EmbeddedUrl = null, Intent = null
            };                                             // create with an empty default, for bot-command messages (those that are not fed through LUIS)

            if (string.IsNullOrEmpty(botMessageResponse))  // nothing from bot-commands, so try doing something with LUIS
            {
                // Run async method in this sync method  (read https://cpratt.co/async-tips-tricks/)
                intentResponse = AsyncHelper.RunSync(() => _luisService.GetIntentAsync(e.ChatMessage.Message.Trim()));

                decimal certaintyThreshold;

                if (!decimal.TryParse(_luisConfiguration.LuisChatCertaintyThreshold, out certaintyThreshold))
                {
                    throw new ArgumentException(nameof(_luisConfiguration.LuisChatCertaintyThreshold));
                }


                if (intentResponse.Certainty > certaintyThreshold)
                {
                    botMessageResponse = _chatMessageService.MapLuisIntentToResponse(intentResponse);
                }
            }

            AddTwitchUserChatRecordToDb(e, intentResponse);
            _twitchClient.SendMessage(_twitchConfiguration.ChannelName, botMessageResponse);
        }