public TrackCommands(Logger.Logger logger, IPrefixService prefixService, GuildService guildService, UserService userService, LastFMService lastFmService, SpotifyService spotifyService, WhoKnowsTrackService whoKnowsTrackService, PlayService playService, IUpdateService updateService, IIndexService indexService) { this._logger = logger; this._prefixService = prefixService; this._guildService = guildService; this._userService = userService; this._lastFmService = lastFmService; this._spotifyService = spotifyService; this._whoKnowsTrackService = whoKnowsTrackService; this._playService = playService; this._updateService = updateService; this._indexService = indexService; this._embed = new EmbedBuilder() .WithColor(DiscordConstants.LastFMColorRed); this._embedAuthor = new EmbedAuthorBuilder(); this._embedFooter = new EmbedFooterBuilder(); }
public AlbumCommands(Logger.Logger logger, ILastfmApi lastfmApi, IPrefixService prefixService, UserService userService, LastFMService lastFmService, WhoKnowsAlbumService whoKnowsAlbumService, PlayService playService, IIndexService indexService, IUpdateService updateService) { this._logger = logger; this._lastfmApi = lastfmApi; this._lastFmService = lastFmService; this._whoKnowsAlbumService = whoKnowsAlbumService; this._playService = playService; this._indexService = indexService; this._updateService = updateService; this._prefixService = prefixService; this._guildService = new GuildService(); this._userService = userService; this._embed = new EmbedBuilder() .WithColor(DiscordConstants.LastFMColorRed); this._embedAuthor = new EmbedAuthorBuilder(); this._embedFooter = new EmbedFooterBuilder(); }
public SpotifyCommands(Logger.Logger logger, IPrefixService prefixService, ILastfmApi lastfmApi) { this._logger = logger; this._prefixService = prefixService; this._userService = new UserService(); this._lastFmService = new LastFMService(lastfmApi); this._embed = new EmbedBuilder() .WithColor(Constants.LastFMColorRed); }
public SpotifyCommands( IPrefixService prefixService, LastFMService lastFmService, UserService userService, SpotifyService spotifyService) { this._prefixService = prefixService; this._userService = userService; this._spotifyService = spotifyService; this._lastFmService = lastFmService; this._embed = new EmbedBuilder() .WithColor(DiscordConstants.LastFMColorRed); }
public YoutubeCommands( IPrefixService prefixService, LastFMService lastFmService, UserService userService, YoutubeService youtubeService) { this._prefixService = prefixService; this._userService = userService; this._youtubeService = youtubeService; this._lastFmService = lastFmService; this._embed = new EmbedBuilder() .WithColor(DiscordConstants.LastFMColorRed); }
public GeniusCommands( IPrefixService prefixService, LastFMService lastFmService, UserService userService, GeniusService geniusService) { this._prefixService = prefixService; this._userService = userService; this._geniusService = geniusService; this._lastFmService = lastFmService; this._embed = new EmbedBuilder() .WithColor(DiscordConstants.LastFMColorRed); this._embedFooter = new EmbedFooterBuilder(); }
public ListArtistViewModel() { service = new LastFMService(); service.TrackSearch_Completed += (s, a) => { TrackList = new ObservableCollection <Track>(a.Result.Value); Current = TrackList.First(); }; Title = "Artist"; service.TrackSearch("malone"); }
public TrackCommands(Logger.Logger logger, IPrefixService prefixService, ILastfmApi lastfmApi, GuildService guildService, UserService userService) { this._logger = logger; this._prefixService = prefixService; this._guildService = guildService; this._userService = userService; this._lastFmService = new LastFMService(lastfmApi); this._embed = new EmbedBuilder() .WithColor(Constants.LastFMColorRed); this._embedAuthor = new EmbedAuthorBuilder(); this._embedFooter = new EmbedFooterBuilder(); }
public async Task UnLoveAsync(params string[] trackValues) { var userSettings = await this._userService.GetUserSettingsAsync(this.Context.User); var prfx = this._prefixService.GetPrefix(this.Context.Guild.Id) ?? ConfigData.Data.Bot.Prefix; if (trackValues.Any() && trackValues.First() == "help") { this._embed.WithTitle($"{prfx}unlove"); this._embed.WithDescription("Unloves the track you're currently listening to or searching for on last.fm."); await this.Context.Channel.SendMessageAsync("", false, this._embed.Build()); this.Context.LogCommandUsed(CommandResponse.Help); return; } _ = this.Context.Channel.TriggerTypingAsync(); var track = await this.SearchTrack(trackValues, userSettings, prfx); if (track == null) { return; } var userTitle = await this._userService.GetUserTitleAsync(this.Context); var trackLoved = await this._lastFmService.UnLoveTrackAsync(userSettings, track.Artist.Name, track.Name); if (trackLoved) { this._embed.WithTitle($"💔 Unloved track for {userTitle}"); this._embed.WithDescription(LastFMService.ResponseTrackToLinkedString(track)); } else { await this.Context.Message.Channel.SendMessageAsync( "Something went wrong while unloving track."); this.Context.LogCommandUsed(CommandResponse.Error); return; } await this.Context.Channel.SendMessageAsync("", false, this._embed.Build()); this.Context.LogCommandUsed(); }
public ChartCommands( IPrefixService prefixService, IChartService chartService, GuildService guildService, UserService userService, LastFMService lastFmService) { this._prefixService = prefixService; this._chartService = chartService; this._guildService = guildService; this._userService = userService; this._lastFmService = lastFmService; this._embed = new EmbedBuilder() .WithColor(DiscordConstants.LastFMColorRed); this._embedAuthor = new EmbedAuthorBuilder(); this._embedFooter = new EmbedFooterBuilder(); }
public FriendsCommands( IPrefixService prefixService, GuildService guildService, LastFMService lastFmService, UserService userService, FriendsService friendsService) { this._prefixService = prefixService; this._guildService = guildService; this._userService = userService; this._friendsService = friendsService; this._lastFmService = lastFmService; this._embed = new EmbedBuilder() .WithColor(Constants.LastFMColorRed); this._embedAuthor = new EmbedAuthorBuilder(); this._embedFooter = new EmbedFooterBuilder(); }
public UserCommands(TimerService timer, Logger.Logger logger, IPrefixService prefixService, ILastfmApi lastfmApi, GuildService guildService) { this._timer = timer; this._logger = logger; this._prefixService = prefixService; this._guildService = guildService; this._friendsService = new FriendsService(); this._userService = new UserService(); this._lastFmService = new LastFMService(lastfmApi); this._embed = new EmbedBuilder() .WithColor(Constants.LastFMColorRed); this._embedAuthor = new EmbedAuthorBuilder(); this._embedFooter = new EmbedFooterBuilder(); }
public async void Run(IBackgroundTaskInstance taskInstance) { var deferral = taskInstance.GetDeferral(); if (SettingsService.Instance.LiveTile) { using (var lastFmService = new LastFMService()) { await lastFmService.Login(); var artists = await lastFmService.RecentTopArtists(); if (artists.Any()) { UpdateTile(artists); } } } deferral.Complete(); }
public ArtistCommands(Logger.Logger logger, ILastfmApi lastfmApi, IPrefixService prefixService, ArtistsService artistsService, WhoKnowsService whoKnowsService, GuildService guildService, UserService userService) { this._logger = logger; this._lastfmApi = lastfmApi; this._lastFmService = new LastFMService(lastfmApi); this._prefixService = prefixService; this._artistsService = artistsService; this._whoKnowsService = whoKnowsService; this._guildService = guildService; this._userService = userService; this._embed = new EmbedBuilder() .WithColor(Constants.LastFMColorRed); this._embedAuthor = new EmbedAuthorBuilder(); this._embedFooter = new EmbedFooterBuilder(); }
public PlayCommands( IPrefixService prefixService, GuildService guildService, UserService userService, LastFMService lastFmService, PlayService playService, IUpdateService updateService, IIndexService indexService) { this._prefixService = prefixService; this._guildService = guildService; this._userService = userService; this._lastFmService = lastFmService; this._playService = playService; this._updateService = updateService; this._indexService = indexService; this._embed = new EmbedBuilder() .WithColor(DiscordConstants.LastFMColorRed); this._embedAuthor = new EmbedAuthorBuilder(); this._embedFooter = new EmbedFooterBuilder(); }
public UserCommands(TimerService timer, Logger.Logger logger, IPrefixService prefixService, GuildService guildService, LastFMService lastFmService, IIndexService indexService, UserService userService, FriendsService friendsService) { this._timer = timer; this._logger = logger; this._prefixService = prefixService; this._guildService = guildService; this._friendsService = friendsService; this._userService = userService; this._lastFmService = lastFmService; this._indexService = indexService; this._embed = new EmbedBuilder() .WithColor(DiscordConstants.LastFMColorRed); this._embedAuthor = new EmbedAuthorBuilder(); this._embedFooter = new EmbedFooterBuilder(); }
public async Task RecentAsync(string amount = "5", string user = null) { var userSettings = await this._userService.GetUserSettingsAsync(this.Context.User); var prfx = this._prefixService.GetPrefix(this.Context.Guild.Id) ?? ConfigData.Data.Bot.Prefix; if (user == "help") { await ReplyAsync($"{prfx}recent 'number of items (max 10)' 'lastfm username/discord user'"); return; } if (!int.TryParse(amount, out var amountOfTracks)) { await ReplyAsync("Please enter a valid amount. \n" + $"`{prfx}recent 'number of items (max 10)' 'lastfm username/discord user'` \n" + $"Example: `{prfx}recent 8`"); return; } if (amountOfTracks > 10) { amountOfTracks = 10; } if (amountOfTracks < 1) { amountOfTracks = 1; } try { var lastFMUserName = userSettings.UserNameLastFM; var self = true; if (user != null) { var alternativeLastFmUserName = await FindUser(user); if (!string.IsNullOrEmpty(alternativeLastFmUserName)) { lastFMUserName = alternativeLastFmUserName; self = false; } } var tracksTask = this._lastFmService.GetRecentScrobblesAsync(lastFMUserName, amountOfTracks); var userInfoTask = this._lastFmService.GetUserInfoAsync(lastFMUserName); Task.WaitAll(tracksTask, userInfoTask); var tracks = tracksTask.Result; var userInfo = userInfoTask.Result; if (tracks?.Any() != true) { this._embed.NoScrobblesFoundErrorResponse(tracks.Status, this.Context, this._logger); await ReplyAsync("", false, this._embed.Build()); return; } var userTitle = await this._userService.GetUserTitleAsync(this.Context); var title = self ? userTitle : $"{lastFMUserName}, requested by {userTitle}"; this._embedAuthor.WithName($"Latest tracks for {title}"); this._embedAuthor.WithIconUrl(this.Context.User.GetAvatarUrl()); this._embedAuthor.WithUrl(Constants.LastFMUserUrl + lastFMUserName); this._embed.WithAuthor(this._embedAuthor); var fmRecentText = ""; for (var i = 0; i < tracks.Content.Count; i++) { var track = tracks.Content[i]; if (i == 0) { var albumImages = await this._lastFmService.GetAlbumImagesAsync(track.ArtistName, track.AlbumName); if (albumImages?.Medium != null) { this._embed.WithThumbnailUrl(albumImages.Medium.ToString()); } } fmRecentText += $"`{i + 1}` {LastFMService.TrackToLinkedString(track)}\n"; } this._embed.WithDescription(fmRecentText); string footerText; if (tracks.Content[0].IsNowPlaying == true) { footerText = $"{userInfo.Content.Name} has {userInfo.Content.Playcount} scrobbles - Now Playing"; } else { footerText = $"{userInfo.Content.Name} has {userInfo.Content.Playcount} scrobbles"; if (tracks.Content[0].TimePlayed.HasValue) { footerText += " - Last scrobble:"; this._embed.WithTimestamp(tracks.Content[0].TimePlayed.Value); } } this._embedFooter.WithText(footerText); this._embed.WithFooter(this._embedFooter); await this.Context.Channel.SendMessageAsync("", false, this._embed.Build()); this._logger.LogCommandUsed(this.Context.Guild?.Id, this.Context.Channel.Id, this.Context.User.Id, this.Context.Message.Content); } catch (Exception e) { this._logger.LogError(e.Message, this.Context.Message.Content, this.Context.User.Username, this.Context.Guild?.Name, this.Context.Guild?.Id); await ReplyAsync( "Unable to show your recent tracks on Last.FM due to an internal error. Try setting a Last.FM name with the 'fmset' command, scrobbling something, and then use the command again."); } }
public async Task FriendsAsync() { var userSettings = await this._userService.GetUserSettingsAsync(this.Context.User, bypassCache : true); try { var friends = await this._friendsService.GetFMFriendsAsync(this.Context.User); if (friends?.Any() != true) { await ReplyAsync("We couldn't find any friends. To add friends:\n" + "`.fmaddfriends 'lastfmname/discord name'`"); this.Context.LogCommandUsed(CommandResponse.NotFound); return; } _ = this.Context.Channel.TriggerTypingAsync(); var embedFooterText = "Amount of scrobbles of all your friends together: "; string embedTitle; if (friends.Count > 1) { embedTitle = $"Last songs for {friends.Count} friends from "; } else { embedTitle = "Last songs for 1 friend from "; embedFooterText = "Amount of scrobbles from your friend: "; } embedTitle += await this._userService.GetUserTitleAsync(this.Context); this._embedAuthor.WithName(embedTitle); this._embedAuthor.WithIconUrl(this.Context.User.GetAvatarUrl()); this._embedAuthor.WithUrl(Constants.LastFMUserUrl + userSettings.UserNameLastFM); this._embed.WithAuthor(this._embedAuthor); var totalPlaycount = 0; var embedDescription = ""; await friends.ParallelForEachAsync(async friend => { var tracks = await this._lastFmService.GetRecentScrobblesAsync(friend, 1); string track; string friendTitle = friend; if (!tracks.Success) { track = "Friend could not be retrieved"; } else if (tracks?.Any() != true) { track = "No scrobbles found."; } else { var lastTrack = tracks.Content[0]; track = LastFMService.TrackToOneLinedString(lastTrack); if (lastTrack.IsNowPlaying == true) { friendTitle += " (Now Playing)"; } if (friends.Count <= 5) { var userInfo = await this._lastFmService.GetUserInfoAsync(friend); totalPlaycount += userInfo.Content.Playcount; } } embedDescription += $"[{friendTitle}]({Constants.LastFMUserUrl}{friend}) - {track} \n"; }); if (friends.Count <= 5) { this._embedFooter.WithText(embedFooterText + totalPlaycount.ToString("0")); this._embed.WithFooter(this._embedFooter); } this._embed.WithDescription(embedDescription); await this.Context.Channel.SendMessageAsync("", false, this._embed.Build()); this.Context.LogCommandUsed(); } catch (Exception e) { this.Context.LogCommandException(e); await ReplyAsync( "Unable to show friends due to an internal error."); } }
public async Task AlbumCoverAsync() { var userSettings = await this._userService.GetUserSettingsAsync(this.Context.User); if (userSettings?.UserNameLastFM == null) { this._embed.UsernameNotSetErrorResponse(this.Context, this._logger); await ReplyAsync("", false, this._embed.Build()); return; } var tracks = await this._lastFmService.GetRecentScrobblesAsync(userSettings.UserNameLastFM, 1); if (tracks?.Any() != true) { this._embed.NoScrobblesFoundErrorResponse(tracks.Status, this.Context, this._logger); await ReplyAsync("", false, this._embed.Build()); return; } var currentTrack = tracks.Content[0]; var albumInfo = await this._lastFmService.GetAlbumImagesAsync(currentTrack.ArtistName, currentTrack.AlbumName); if (albumInfo.Largest == null) { this._embed.WithDescription("Sorry, no album cover found for this album: \n" + $"{currentTrack.ArtistName} - {currentTrack.AlbumName}\n" + $"[View on last.fm]({currentTrack.Url})"); await ReplyAsync("", false, this._embed.Build()); return; } var image = await this._lastFmService.GetAlbumImageAsBitmapAsync(albumInfo.Largest); if (image == null) { this._embed.WithDescription("Sorry, something went wrong while getting album cover for this album: \n" + $"{currentTrack.ArtistName} - {currentTrack.AlbumName}\n" + $"[View on last.fm]({currentTrack.Url})"); await ReplyAsync("", false, this._embed.Build()); return; } this._embed.WithDescription(LastFMService.TrackToLinkedString(currentTrack)); this._embedFooter.WithText( $"Album cover requested by {await this._userService.GetUserTitleAsync(this.Context)}"); this._embed.WithFooter(this._embedFooter); var imageMemoryStream = new MemoryStream(); image.Save(imageMemoryStream, ImageFormat.Png); imageMemoryStream.Position = 0; await this.Context.Channel.SendFileAsync( imageMemoryStream, $"cover-{currentTrack.Mbid}.png", null, false, this._embed.Build()); this._logger.LogCommandUsed(this.Context.Guild?.Id, this.Context.Channel.Id, this.Context.User.Id, this.Context.Message.Content); }
public async Task TopArtistsAsync(string time = "weekly", int num = 10, string user = null) { var userSettings = await this._userService.GetUserSettingsAsync(this.Context.User); var prfx = this._prefixService.GetPrefix(this.Context.Guild.Id) ?? ConfigData.Data.Bot.Prefix; if (time == "help") { await ReplyAsync( $"Usage: `{prfx}artists '{Constants.CompactTimePeriodList}' 'number of artists (max 16)' 'lastfm username/discord user'`"); return; } _ = this.Context.Channel.TriggerTypingAsync(); if (num > 16) { num = 16; } if (num < 1) { num = 1; } var timePeriod = LastFMService.StringToChartTimePeriod(time); var timeSpan = LastFMService.ChartTimePeriodToLastStatsTimeSpan(timePeriod); try { var lastFMUserName = userSettings.UserNameLastFM; var self = true; if (user != null) { var alternativeLastFmUserName = await FindUser(user); if (!string.IsNullOrEmpty(alternativeLastFmUserName)) { lastFMUserName = alternativeLastFmUserName; self = false; } } var artists = await this._lastFmService.GetTopArtistsAsync(lastFMUserName, timeSpan, num); if (artists?.Any() != true) { this._embed.NoScrobblesFoundErrorResponse(artists.Status, this.Context, this._logger); await ReplyAsync("", false, this._embed.Build()); return; } string userTitle; if (self) { userTitle = await this._userService.GetUserTitleAsync(this.Context); } else { userTitle = $"{lastFMUserName}, requested by {await this._userService.GetUserTitleAsync(this.Context)}"; } this._embedAuthor.WithIconUrl(this.Context.User.GetAvatarUrl()); var artistsString = num == 1 ? "artist" : "artists"; this._embedAuthor.WithName($"Top {num} {timePeriod} {artistsString} for {userTitle}"); this._embedAuthor.WithUrl($"{Constants.LastFMUserUrl}{lastFMUserName}/library/artists?date_preset={LastFMService.ChartTimePeriodToSiteTimePeriodUrl(timePeriod)}"); this._embed.WithAuthor(this._embedAuthor); var description = ""; for (var i = 0; i < artists.Count(); i++) { var artist = artists.Content[i]; description += $"{i + 1}. [{artist.Name}]({artist.Url}) ({artist.PlayCount} plays) \n"; } this._embed.WithDescription(description); var userInfo = await this._lastFmService.GetUserInfoAsync(lastFMUserName); this._embedFooter.WithText(lastFMUserName + "'s total scrobbles: " + userInfo.Content.Playcount.ToString("N0")); this._embed.WithFooter(this._embedFooter); await this.Context.Channel.SendMessageAsync("", false, this._embed.Build()); this._logger.LogCommandUsed(this.Context.Guild?.Id, this.Context.Channel.Id, this.Context.User.Id, this.Context.Message.Content); } catch (Exception e) { this._logger.LogError(e.Message, this.Context.Message.Content, this.Context.User.Username, this.Context.Guild?.Name, this.Context.Guild?.Id); await ReplyAsync("Unable to show Last.FM info due to an internal error."); } }
public async Task FMAsync(params string[] user) { var userSettings = await this._userService.GetUserSettingsAsync(this.Context.User); var prfx = this._prefixService.GetPrefix(this.Context.Guild.Id) ?? ConfigData.Data.Bot.Prefix; if (userSettings?.UserNameLastFM == null) { this._embed.UsernameNotSetErrorResponse(this.Context, prfx, this._logger); await ReplyAsync("", false, this._embed.Build()); return; } if (user.Length > 0 && user.First() == "help") { var fmString = "fm"; if (prfx == ".fm") { fmString = ""; } var replyString = $"`{prfx}{fmString}` shows you your last scrobble(s). \n " + $"This command can also be used on others, for example `{prfx}{fmString} lastfmusername` or `{prfx}{fmString} @discorduser`\n \n" + "You can set your username and you can change the mode with the `.fmset` command.\n"; var differentMode = userSettings.FmEmbedType == FmEmbedType.embedmini ? "embedfull" : "embedmini"; replyString += $"`{prfx}set {userSettings.UserNameLastFM} {differentMode}` \n \n" + $"For more info, use `{prfx}set help`."; this._embed.WithUrl($"{Constants.DocsUrl}/commands/tracks/"); this._embed.WithTitle($"Using the {prfx}{fmString} command"); this._embed.WithDescription(replyString); await this.Context.Channel.SendMessageAsync("", false, this._embed.Build()); return; } if (user.Length > 0 && user.First() == "set") { await ReplyAsync( "Please remove the space between `.fm` and `set` to set your last.fm username."); return; } try { var lastFMUserName = userSettings.UserNameLastFM; var self = true; if (user.Length > 0 && !string.IsNullOrEmpty(user.First())) { var alternativeLastFmUserName = await FindUser(user.First()); if (!string.IsNullOrEmpty(alternativeLastFmUserName) && await this._lastFmService.LastFMUserExistsAsync(alternativeLastFmUserName)) { lastFMUserName = alternativeLastFmUserName; self = false; } } var recentScrobblesTask = this._lastFmService.GetRecentScrobblesAsync(lastFMUserName); var userInfoTask = this._lastFmService.GetUserInfoAsync(lastFMUserName); Task.WaitAll(recentScrobblesTask, userInfoTask); var recentScrobbles = recentScrobblesTask.Result; var userInfo = userInfoTask.Result; if (recentScrobbles?.Any() != true) { this._embed.NoScrobblesFoundErrorResponse(recentScrobbles.Status, this.Context, this._logger); await ReplyAsync("", false, this._embed.Build()); return; } var currentTrack = recentScrobbles.Content[0]; var previousTrack = recentScrobbles.Content[1]; var playCount = userInfo.Content.Playcount; var userTitle = await this._userService.GetUserTitleAsync(this.Context); var embedTitle = self ? userTitle : $"{lastFMUserName}, requested by {userTitle}"; var fmText = ""; string footerText = ""; footerText += $"{userInfo.Content.Name} has "; switch (userSettings.FmCountType) { case FmCountType.Track: var trackInfo = await this._lastFmService.GetTrackInfoAsync(currentTrack.Name, currentTrack.ArtistName, lastFMUserName); if (trackInfo != null) { footerText += $"{trackInfo.Userplaycount} scrobbles on this track | "; } break; case FmCountType.Album: if (!string.IsNullOrEmpty(currentTrack.AlbumName)) { var albumInfo = await this._lastFmService.GetAlbumInfoAsync(currentTrack.ArtistName, currentTrack.AlbumName, lastFMUserName); if (albumInfo.Success) { footerText += $"{albumInfo.Content.Album.Userplaycount} scrobbles on this album | "; } } break; case FmCountType.Artist: var artistInfo = await this._lastFmService.GetArtistInfoAsync(currentTrack.ArtistName, lastFMUserName); if (artistInfo.Success) { footerText += $"{artistInfo.Content.Artist.Stats.Userplaycount} scrobbles on this artist | "; } break; } footerText += $"{userInfo.Content.Playcount} total scrobbles"; switch (userSettings.FmEmbedType) { case FmEmbedType.textmini: case FmEmbedType.textfull: if (userSettings.FmEmbedType == FmEmbedType.textmini) { fmText += $"Last track for {embedTitle}: \n"; fmText += LastFMService.TrackToString(currentTrack); } else { fmText += $"Last tracks for {embedTitle}: \n"; fmText += LastFMService.TrackToString(currentTrack); fmText += LastFMService.TrackToString(previousTrack); } fmText += $"<{Constants.LastFMUserUrl + userSettings.UserNameLastFM}> has {playCount} scrobbles."; fmText = fmText.FilterOutMentions(); await this.Context.Channel.SendMessageAsync(fmText); break; default: var albumImagesTask = this._lastFmService.GetAlbumImagesAsync(currentTrack.ArtistName, currentTrack.AlbumName); if (!this._guildService.CheckIfDM(this.Context)) { var perms = await this._guildService.CheckSufficientPermissionsAsync(this.Context); if (!perms.EmbedLinks) { await ReplyAsync( "Insufficient permissions, I need to the 'Embed links' permission to show you your scrobbles."); break; } } if (userSettings.FmEmbedType == FmEmbedType.embedmini) { fmText += LastFMService.TrackToLinkedString(currentTrack); this._embed.WithDescription(fmText); } else { this._embed.AddField("Current:", LastFMService.TrackToLinkedString(currentTrack)); this._embed.AddField("Previous:", LastFMService.TrackToLinkedString(previousTrack)); } string headerText; if (currentTrack.IsNowPlaying == true) { headerText = "Now playing - "; } else { headerText = userSettings.FmEmbedType == FmEmbedType.embedmini ? "Last track for " : "Last tracks for "; } headerText += embedTitle; if (currentTrack.IsNowPlaying != true && currentTrack.TimePlayed.HasValue) { footerText += " | Last scrobble:"; this._embed.WithTimestamp(currentTrack.TimePlayed.Value); } this._embedAuthor.WithName(headerText); this._embedAuthor.WithUrl(Constants.LastFMUserUrl + lastFMUserName); this._embedFooter.WithText(footerText); this._embed.WithFooter(this._embedFooter); this._embedAuthor.WithIconUrl(this.Context.User.GetAvatarUrl()); this._embed.WithAuthor(this._embedAuthor); this._embed.WithUrl(Constants.LastFMUserUrl + lastFMUserName); if ((await albumImagesTask)?.Large != null) { this._embed.WithThumbnailUrl((await albumImagesTask).Large.ToString()); } var message = await ReplyAsync("", false, this._embed.Build()); if (!this._guildService.CheckIfDM(this.Context)) { await this._guildService.AddReactionsAsync(message, this.Context.Guild); } break; } this._logger.LogCommandUsed(this.Context.Guild?.Id, this.Context.Channel.Id, this.Context.User.Id, this.Context.Message.Content); } catch (Exception e) { this._logger.LogError(e.Message, this.Context.Message.Content, this.Context.User.Username, this.Context.Guild?.Name, this.Context.Guild?.Id); await ReplyAsync( "Unable to show Last.FM info due to an internal error. Try scrobbling something then use the command again."); } }
public async Task TasteAsync(string user = null, params string[] extraOptions) { var userSettings = await this._userService.GetUserSettingsAsync(this.Context.User); var prfx = this._prefixService.GetPrefix(this.Context.Guild.Id) ?? ConfigData.Data.Bot.Prefix; if (user == "help") { await ReplyAsync( $"Usage: `{prfx}taste 'last.fm username/ discord mention' '{Constants.CompactTimePeriodList}' 'table/embed'`"); this.Context.LogCommandUsed(CommandResponse.Help); return; } _ = this.Context.Channel.TriggerTypingAsync(); var timeType = LastFMService.StringOptionsToSettings( extraOptions, LastStatsTimeSpan.Overall, ChartTimePeriod.AllTime, "ALL", "overall"); var tasteSettings = new TasteSettings { ChartTimePeriod = timeType.ChartTimePeriod }; tasteSettings = this._artistsService.SetTasteSettings(tasteSettings, extraOptions); try { var ownLastFmUsername = userSettings.UserNameLastFM; string lastfmToCompare = null; if (user != null) { var alternativeLastFmUserName = await FindUser(user); if (!string.IsNullOrEmpty(alternativeLastFmUserName)) { lastfmToCompare = alternativeLastFmUserName; } } if (lastfmToCompare == null) { await ReplyAsync( $"Please enter a valid user to compare your top artists to. \n" + $"Example: `{prfx}taste lastfmusername` or `{prfx}taste @user`"); this.Context.LogCommandUsed(CommandResponse.WrongInput); return; } if (lastfmToCompare.ToLower() == userSettings.UserNameLastFM.ToLower()) { await ReplyAsync( $"You can't compare your own taste with yourself. For viewing your top artists, use `fmtopartists`\n" + $"Please enter a different last.fm username or mention another user."); this.Context.LogCommandUsed(CommandResponse.WrongInput); return; } tasteSettings.OtherUserLastFmUsername = lastfmToCompare; var ownArtistsTask = this._lastFmService.GetTopArtistsAsync(ownLastFmUsername, timeType.LastStatsTimeSpan, 1000); var otherArtistsTask = this._lastFmService.GetTopArtistsAsync(lastfmToCompare, timeType.LastStatsTimeSpan, 1000); Task.WaitAll(ownArtistsTask, otherArtistsTask); var ownArtists = await ownArtistsTask; var otherArtists = await otherArtistsTask; if (ownArtists?.Any() != true || otherArtists?.Any() != true) { await ReplyAsync( $"You or the other user don't have any artist plays in the selected time period."); this.Context.LogCommandUsed(CommandResponse.NoScrobbles); return; } this._embedAuthor.WithIconUrl(this.Context.User.GetAvatarUrl()); this._embedAuthor.WithName($"Top artist comparison - {ownLastFmUsername} vs {lastfmToCompare}"); this._embedAuthor.WithUrl($"{Constants.LastFMUserUrl}{lastfmToCompare}/library/artists?date_preset={timeType.UrlParameter}"); this._embed.WithAuthor(this._embedAuthor); int amount = 14; if (tasteSettings.TasteType == TasteType.FullEmbed) { var taste = await this._artistsService.GetEmbedTasteAsync(ownArtists, otherArtists, amount, timeType.ChartTimePeriod); this._embed.WithDescription(taste.Description); this._embed.AddField("Artist", taste.LeftDescription, true); this._embed.AddField("Plays", taste.RightDescription, true); } else { var taste = await this._artistsService.GetTableTasteAsync(ownArtists, otherArtists, amount, timeType.ChartTimePeriod, ownLastFmUsername, lastfmToCompare); this._embed.WithDescription(taste); } await this.Context.Channel.SendMessageAsync("", false, this._embed.Build()); this.Context.LogCommandUsed(); } catch (Exception e) { this.Context.LogCommandException(e); await ReplyAsync("Unable to show Last.FM info due to an internal error."); } }
public async Task TopArtistsAsync(params string[] extraOptions) { var userSettings = await this._userService.GetUserSettingsAsync(this.Context.User); var prfx = this._prefixService.GetPrefix(this.Context.Guild.Id) ?? ConfigData.Data.Bot.Prefix; if (extraOptions.Any() && extraOptions.First() == "help") { this._embed.WithTitle($"{prfx}topartists options"); this._embed.WithDescription($"- `{Constants.CompactTimePeriodList}`\n" + $"- `number of artists (max 16)`\n" + $"- `user mention/id`"); this._embed.AddField("Example", $"`{prfx}topartists @drasil alltime 11`"); await this.Context.Channel.SendMessageAsync("", false, this._embed.Build()); this.Context.LogCommandUsed(CommandResponse.Help); return; } _ = this.Context.Channel.TriggerTypingAsync(); var settings = LastFMService.StringOptionsToSettings(extraOptions); try { var lastFMUserName = userSettings.UserNameLastFM; var self = true; if (settings.OtherDiscordUserId.HasValue) { var alternativeLastFmUserName = await FindUserFromId(settings.OtherDiscordUserId.Value); if (!string.IsNullOrEmpty(alternativeLastFmUserName)) { lastFMUserName = alternativeLastFmUserName; self = false; } } var artists = await this._lastFmService.GetTopArtistsAsync(lastFMUserName, settings.LastStatsTimeSpan, settings.Amount); if (artists?.Any() != true) { this._embed.NoScrobblesFoundErrorResponse(artists.Status, prfx); this.Context.LogCommandUsed(CommandResponse.NoScrobbles); await ReplyAsync("", false, this._embed.Build()); return; } string userTitle; if (self) { userTitle = await this._userService.GetUserTitleAsync(this.Context); } else { userTitle = $"{lastFMUserName}, requested by {await this._userService.GetUserTitleAsync(this.Context)}"; } this._embedAuthor.WithIconUrl(this.Context.User.GetAvatarUrl()); var artistsString = settings.Amount == 1 ? "artist" : "artists"; this._embedAuthor.WithName($"Top {settings.Amount} {settings.Description.ToLower()} {artistsString} for {userTitle}"); this._embedAuthor.WithUrl($"{Constants.LastFMUserUrl}{lastFMUserName}/library/artists?date_preset={settings.UrlParameter}"); this._embed.WithAuthor(this._embedAuthor); var description = ""; for (var i = 0; i < artists.Count(); i++) { var artist = artists.Content[i]; description += $"{i + 1}. [{artist.Name}]({artist.Url}) ({artist.PlayCount} plays) \n"; } this._embed.WithDescription(description); var userInfo = await this._lastFmService.GetUserInfoAsync(lastFMUserName); this._embedFooter.WithText(lastFMUserName + "'s total scrobbles: " + userInfo.Content.Playcount.ToString("N0")); this._embed.WithFooter(this._embedFooter); await this.Context.Channel.SendMessageAsync("", false, this._embed.Build()); this.Context.LogCommandUsed(); } catch (Exception e) { this.Context.LogCommandException(e); await ReplyAsync("Unable to show Last.FM info due to an internal error."); } }
public async Task TopTracksAsync(string time = "weekly", int num = 8, string user = null) { var userSettings = await this._userService.GetUserSettingsAsync(this.Context.User); var prfx = this._prefixService.GetPrefix(this.Context.Guild.Id) ?? ConfigData.Data.Bot.Prefix; if (time == "help") { await ReplyAsync( $"Usage: `.fmtoptracks '{Constants.CompactTimePeriodList}' 'number of tracks (max 12)' 'lastfm username/discord user'`"); return; } _ = this.Context.Channel.TriggerTypingAsync(); if (num > 12) { num = 12; } if (num < 1) { num = 1; } var timePeriod = LastFMService.StringToChartTimePeriod(time); var timeSpan = LastFMService.ChartTimePeriodToCallTimePeriod(timePeriod); try { var lastFMUserName = userSettings.UserNameLastFM; var self = true; if (user != null) { var alternativeLastFmUserName = await FindUser(user); if (!string.IsNullOrEmpty(alternativeLastFmUserName)) { lastFMUserName = alternativeLastFmUserName; self = false; } } var topTracks = await this._lastFmService.GetTopTracksAsync(lastFMUserName, timeSpan, num); var userUrl = $"{Constants.LastFMUserUrl}{lastFMUserName}/library/tracks?date_preset={LastFMService.ChartTimePeriodToSiteTimePeriodUrl(timePeriod)}"; if (!topTracks.Success) { this._embed.ErrorResponse(topTracks.Error.Value, topTracks.Message, this.Context, this._logger); await ReplyAsync("", false, this._embed.Build()); return; } if (!topTracks.Content.TopTracks.Track.Any()) { this._embed.WithDescription("No top tracks returned for selected time period.\n" + $"View [track history here]{userUrl}"); this._embed.WithColor(Constants.WarningColorOrange); await ReplyAsync("", false, this._embed.Build()); return; } string userTitle; if (self) { userTitle = await this._userService.GetUserTitleAsync(this.Context); } else { userTitle = $"{lastFMUserName}, requested by {await this._userService.GetUserTitleAsync(this.Context)}"; } this._embedAuthor.WithIconUrl(this.Context.User.GetAvatarUrl()); var artistsString = num == 1 ? "track" : "tracks"; this._embedAuthor.WithName($"Top {num} {timePeriod} {artistsString} for {userTitle}"); this._embedAuthor.WithUrl(userUrl); this._embed.WithAuthor(this._embedAuthor); var description = ""; for (var i = 0; i < topTracks.Content.TopTracks.Track.Count; i++) { var track = topTracks.Content.TopTracks.Track[i]; description += $"{i + 1}. [{track.Artist.Name}]({track.Artist.Url}) - [{track.Name}]({track.Url}) ({track.Playcount} plays) \n"; } this._embed.WithDescription(description); var userInfo = await this._lastFmService.GetUserInfoAsync(lastFMUserName); this._embedFooter.WithText(lastFMUserName + "'s total scrobbles: " + userInfo.Content.Playcount.ToString("N0")); this._embed.WithFooter(this._embedFooter); await this.Context.Channel.SendMessageAsync("", false, this._embed.Build()); this._logger.LogCommandUsed(this.Context.Guild?.Id, this.Context.Channel.Id, this.Context.User.Id, this.Context.Message.Content); } catch (Exception e) { this._logger.LogError(e.Message, this.Context.Message.Content, this.Context.User.Username, this.Context.Guild?.Name, this.Context.Guild?.Id); await ReplyAsync("Unable to show Last.FM info due to an internal error."); } }
public async Task TopTracksAsync(params string[] extraOptions) { var userSettings = await this._userService.GetUserSettingsAsync(this.Context.User); var prfx = this._prefixService.GetPrefix(this.Context.Guild.Id) ?? ConfigData.Data.Bot.Prefix; if (extraOptions.Any() && extraOptions.First() == "help") { this._embed.WithTitle($"{prfx}toptracks options"); this._embed.WithDescription($"- `{Constants.CompactTimePeriodList}`\n" + $"- `number of tracks (max 16)`\n" + $"- `user mention/id`"); this._embed.AddField("Example", $"`{prfx}toptracks alltime @john 11`"); await this.Context.Channel.SendMessageAsync("", false, this._embed.Build()); this._logger.LogCommandUsed(this.Context.Guild?.Id, this.Context.Channel.Id, this.Context.User.Id, this.Context.Message.Content); return; } _ = this.Context.Channel.TriggerTypingAsync(); var settings = LastFMService.StringOptionsToSettings(extraOptions); try { var lastFMUserName = userSettings.UserNameLastFM; var self = true; if (settings.OtherDiscordUserId.HasValue) { var alternativeLastFmUserName = await FindUserFromId(settings.OtherDiscordUserId.Value); if (!string.IsNullOrEmpty(alternativeLastFmUserName)) { lastFMUserName = alternativeLastFmUserName; self = false; } } var topTracks = await this._lastFmService.GetTopTracksAsync(lastFMUserName, settings.ApiParameter, settings.Amount); var userUrl = $"{Constants.LastFMUserUrl}{lastFMUserName}/library/tracks?date_preset={settings.UrlParameter}"; if (!topTracks.Success) { this._embed.ErrorResponse(topTracks.Error.Value, topTracks.Message, this.Context, this._logger); await ReplyAsync("", false, this._embed.Build()); return; } if (!topTracks.Content.TopTracks.Track.Any()) { this._embed.WithDescription("No top tracks returned for selected time period.\n" + $"View [track history here]{userUrl}"); this._embed.WithColor(Constants.WarningColorOrange); await ReplyAsync("", false, this._embed.Build()); return; } string userTitle; if (self) { userTitle = await this._userService.GetUserTitleAsync(this.Context); } else { userTitle = $"{lastFMUserName}, requested by {await this._userService.GetUserTitleAsync(this.Context)}"; } this._embedAuthor.WithIconUrl(this.Context.User.GetAvatarUrl()); var artistsString = settings.Amount == 1 ? "track" : "tracks"; this._embedAuthor.WithName($"Top {settings.Amount} {settings.Description.ToLower()} {artistsString} for {userTitle}"); this._embedAuthor.WithUrl(userUrl); this._embed.WithAuthor(this._embedAuthor); var description = ""; for (var i = 0; i < topTracks.Content.TopTracks.Track.Count; i++) { var track = topTracks.Content.TopTracks.Track[i]; description += $"{i + 1}. [{track.Artist.Name}]({track.Artist.Url}) - [{track.Name}]({track.Url}) ({track.Playcount} plays) \n"; } this._embed.WithDescription(description); var userInfo = await this._lastFmService.GetUserInfoAsync(lastFMUserName); this._embedFooter.WithText(lastFMUserName + "'s total scrobbles: " + userInfo.Content.Playcount.ToString("N0")); this._embed.WithFooter(this._embedFooter); await this.Context.Channel.SendMessageAsync("", false, this._embed.Build()); this._logger.LogCommandUsed(this.Context.Guild?.Id, this.Context.Channel.Id, this.Context.User.Id, this.Context.Message.Content); } catch (Exception e) { this._logger.LogError(e.Message, this.Context.Message.Content, this.Context.User.Username, this.Context.Guild?.Name, this.Context.Guild?.Id); await ReplyAsync("Unable to show Last.FM info due to an internal error."); } }