Пример #1
0
        public void GetDownloadCommandArguements_WhenArgIsBadUrl_ReturnNoUrl()
        {
            var uri    = "https://googlcom%";
            var result = new ArguementsHandler($"BoT download {uri}").GetDownloadCommandArguements();

            Assert.Null(result.Uri);
        }
Пример #2
0
        public void GetDownloadCommandArguements_WhenArgIsUrl_ReturnUrlEnumAndValue()
        {
            var uri    = "https://google.com";
            var result = new ArguementsHandler($"BoT download {uri}").GetDownloadCommandArguements().Uri;

            Assert.Equal(result, new Uri(uri));
        }
Пример #3
0
        public void GetDownloadCommandArguements_WhenTimesAreSpecified_ReturnTimeArguements()
        {
            var timeStart = "00:00:01";
            var timeEnd   = "00:00:10";
            var result    = new ArguementsHandler($"BoT download --start {timeStart} --end {timeEnd}").GetDownloadCommandArguements();

            Assert.True(result.Start == timeStart);
            Assert.True(result.End == timeEnd);
        }
Пример #4
0
        public void GetDownloadCommandArguements_WhenAllArguementsAreSpecified_ReturnAll()
        {
            var uri       = "https://google.com";
            var timeStart = "00:00:01";
            var timeEnd   = "00:00:10";
            var result    = new ArguementsHandler($"BoT download --start {timeStart} --end {timeEnd}  {uri}").GetDownloadCommandArguements();

            Assert.True(result.Start == timeStart);
            Assert.True(result.End == timeEnd);
            Assert.Equal(result.Uri, new Uri(uri));
        }
Пример #5
0
        public async Task <IActionResult> Post([FromBody] Activity activity)
        {
            try
            {
                if (activity.Type == ActivityTypes.Message)
                {
                    MicrosoftAppCredentials.TrustServiceUrl(activity.ServiceUrl);

                    var appCredentials = new MicrosoftAppCredentials(this.configuration);
                    var connector      = new ConnectorClient(new Uri(activity.ServiceUrl), appCredentials);

                    var arguments = new ArguementsHandler(activity.Text);
                    if (arguments.CanAction())
                    {
                        var command     = arguments.GetCommand();
                        var userHandler = new UserIntractionHandler(connector, activity);
                        switch (command)
                        {
                        case CommandHandler.Commands.Download:
                            await new CommandHandler(this.download, this.videoConverter).DownloadCommand(arguments, userHandler);
                            break;

                        default:
                            var message = $"Usage: bot download [Optional Commands] [Youtube URL] {Environment.NewLine}";
                            message += $"Where [Commands] is one of: {Environment.NewLine}";
                            message += $"--start HH:MM:SS {Environment.NewLine}";
                            message += $"--end HH:MM:SS {Environment.NewLine}";
                            await userHandler.SendHeroCard("Bot Help", message);

                            break;
                        }
                    }

                    // return our reply to the user
                    // var reply = activity.CreateReply("HelloWorld");
                    // await connector.Conversations.ReplyToActivityAsync(reply);
                }
                else
                {
                    // HandleSystemMessage(activity);
                }

                return(this.Ok());
            }
            catch (Exception ex)
            {
                Console.WriteLine($"{ex.Message} ");
                throw;
            }
        }