Esempio n. 1
0
        public async Task <HttpResultModel <CommandsModel> > PerformResponseUptime(CommandsReadModel commandsReadModel)
        {
            var resultCommandResponse = new HttpResultModel <CommandsModel>();
            var resultStreamInfo      = await GetStreamInformations();

            if (resultStreamInfo.Result && resultStreamInfo.Model.Stream != null)
            {
                var stream        = resultStreamInfo.Model.Stream;
                var nowEuw        = TimeZoneInfo.ConvertTimeBySystemTimeZoneId(DateTime.Now, TZConvert.WindowsToIana("Romance Standard Time"));
                var createdAtEuw  = TimeZoneInfo.ConvertTimeBySystemTimeZoneId(Convert.ToDateTime(stream.Created_at), TZConvert.WindowsToIana("Romance Standard Time"));
                var timeStampDiff = nowEuw - createdAtEuw;
                var message       = $"{timeStampDiff.Hours}h:{timeStampDiff.Minutes}m:{timeStampDiff.Seconds}s";

                var model = new CommandsModel()
                {
                    Response = commandsReadModel.Response.Replace("{uptime}", message)
                };

                resultCommandResponse.PerformResult(true, "", _localizer["Uptime calculé."], model);
                return(resultCommandResponse);
            }
            else
            {
                resultCommandResponse.PerformResult(false, _localizer["Impossible de calculer l'uptime."], "", null);
                return(resultCommandResponse);
            }
        }
        private HttpResultModel <CommandsModel> PerformResponseModel(CommandsReadModel commandsReadModel)
        {
            var resultCommandResponse = new HttpResultModel <CommandsModel>();

            var commandsModel = new CommandsModel()
            {
                Response = commandsReadModel.Response
            };

            resultCommandResponse.PerformResult(true, "", _localizer["Réponse trouvée."], commandsModel);
            return(resultCommandResponse);
        }
        public async Task <HttpResultModel <CommandsModel> > PerformResponseSpotify(CommandsReadModel commandsReadModel, int spotifyType)
        {
            var resultCommandResponse         = new HttpResultModel <CommandsModel>();
            var resultSpotifyCurrentlyPlaying = await SpotifyCurrentlyPlaing();

            if (resultSpotifyCurrentlyPlaying.Result)
            {
                var model = new CommandsModel();

                if (resultSpotifyCurrentlyPlaying.Model != null && resultSpotifyCurrentlyPlaying.Model.IsPlaying)
                {
                    if (spotifyType == (int)SpotifyTypeEnum.MUSIC)
                    {
                        model.Response = commandsReadModel.Response.Replace("{music}", resultSpotifyCurrentlyPlaying.Model.Item.Name).Replace("{artist}", resultSpotifyCurrentlyPlaying.Model.Item.Artists[0].Name);
                    }
                    else if (spotifyType == (int)SpotifyTypeEnum.PLAYLIST)
                    {
                        if (resultSpotifyCurrentlyPlaying.Model.Context != null && resultSpotifyCurrentlyPlaying.Model.Context.ExternalUrls.Spotify != string.Empty)
                        {
                            model.Response = commandsReadModel.Response.Replace("{playlist}", resultSpotifyCurrentlyPlaying.Model.Context.ExternalUrls.Spotify);
                        }
                        else
                        {
                            model.Response = _localizer["Pas de playlist associée au titre en cours."];
                        }
                    }
                }
                else
                {
                    model.Response = _localizer["Pas d'écoute Spotify en cours."];
                }

                resultCommandResponse.PerformResult(true, "", _localizer["Commande music récupérée."], model);
                return(resultCommandResponse);
            }
            else
            {
                resultCommandResponse.PerformResult(false, _localizer["Impossible de récupérer les infos de la musique Spotify."], "", null);
                return(resultCommandResponse);
            }
        }
        public async Task <HttpResultModel <CommandsModel> > GetCommandResponse(CommandsReadModel commandsReadModel)
        {
            var result = new HttpResultModel <CommandsModel>();

            _logger.LogInformation("Command type id : {0}", commandsReadModel.TypeId);

            switch (commandsReadModel.TypeId)
            {
            case (int)CommandsType.Automatic:
            case (int)CommandsType.Response:
                result = PerformResponseModel(commandsReadModel);
                break;

            case (int)CommandsType.Mystery:
                break;

            case (int)CommandsType.Playlist:
                result = await _spotifyBusiness.PerformResponseSpotify(commandsReadModel, (int)SpotifyTypeEnum.PLAYLIST);

                break;

            case (int)CommandsType.Spotify:
                result = await _spotifyBusiness.PerformResponseSpotify(commandsReadModel, (int)SpotifyTypeEnum.MUSIC);

                break;

            case (int)CommandsType.Uptime:
                result = await _uptimeBusiness.PerformResponseUptime(commandsReadModel);

                break;

            default:
                break;
            }

            return(result);
        }