Esempio n. 1
0
        public async Task fmytAsync(IUser user = null)
        {
            Data.Entities.User userSettings = await _userService.GetUserSettingsAsync(Context.User);

            if (userSettings == null || userSettings.UserNameLastFM == null)
            {
                await ReplyAsync("Your LastFM username has not been set. Please set your username using the `.fmset 'username' 'embedfull/embedmini/textfull/textmini'` command.").ConfigureAwait(false);

                return;
            }

            try
            {
                LastTrack track = await _lastFmService.GetLastScrobbleAsync(userSettings.UserNameLastFM).ConfigureAwait(false);

                if (track == null)
                {
                    await ReplyAsync("No scrobbles found on your LastFM profile. (" + userSettings.UserNameLastFM + ")").ConfigureAwait(false);

                    return;
                }

                try
                {
                    string querystring = track.Name + " - " + track.ArtistName;

                    VideoInformation youtubeResult = _youtubeService.GetSearchResult(querystring);

                    await ReplyAsync($"Searched for: `{querystring}`\n " +
                                     youtubeResult.Url).ConfigureAwait(false);

                    this._logger.LogCommandUsed(Context.Guild?.Id, Context.Channel.Id, Context.User.Id, Context.Message.Content);
                }
                catch (Exception e)
                {
                    _logger.LogException(Context.Message.Content, e);
                    await ReplyAsync("No results have been found for this track.").ConfigureAwait(false);
                }
            }
            catch (Exception e)
            {
                _logger.LogException(Context.Message.Content, e);
                await ReplyAsync("Unable to show Last.FM info via YouTube due to an internal error. Try setting a Last.FM name with the 'fmset' command, scrobbling something, and then use the command again.").ConfigureAwait(false);
            }
        }