Exemple #1
0
        public async Task fmserversetAsync([Summary("The default mode you want to use.")] string chartType = "embedmini", [Summary("The default timeperiod you want to use.")] string chartTimePeriod = "monthly")
        {
            if (guildService.CheckIfDM(Context))
            {
                await ReplyAsync("Command is not supported in DMs.").ConfigureAwait(false);

                return;
            }

            IGuildUser serverUser = (IGuildUser)Context.Message.Author;

            if (!serverUser.GuildPermissions.BanMembers && !serverUser.GuildPermissions.Administrator && !await adminService.HasCommandAccessAsync(Context.User, UserType.Admin).ConfigureAwait(false))
            {
                await ReplyAsync("You are not authorized to use this command. Only users with the 'Ban Members' permission, server admins or FMBot admins can use this command.");

                return;
            }
            if (chartType == "help")
            {
                await ReplyAsync("Sets the global default for your server. `.fmserverset 'embedfull/embedmini/textfull/textmini' 'Weekly/Monthly/Yearly/AllTime'` command.");

                return;
            }


            if (!Enum.TryParse(chartType, ignoreCase: true, out ChartType chartTypeEnum))
            {
                await ReplyAsync("Invalid mode. Please use 'embedmini', 'embedfull', 'textfull', or 'textmini'.");

                return;
            }


            if (!Enum.TryParse(chartTimePeriod, ignoreCase: true, out ChartTimePeriod chartTimePeriodEnum))
            {
                await ReplyAsync("Invalid mode. Please use 'weekly', 'monthly', 'yearly', or 'overall'.");

                return;
            }

            await guildService.ChangeGuildSettingAsync(Context.Guild, chartTimePeriodEnum, chartTypeEnum);



            await ReplyAsync("The .fmset default charttype for your server has been set to " + chartTypeEnum + " with the time period " + chartTimePeriodEnum + ".");
        }
Exemple #2
0
        public async Task fmAsync(string user = null)
        {
            User userSettings = await _userService.GetUserSettingsAsync(Context.User);

            if (userSettings?.UserNameLastFM == null)
            {
                await UsernameNotSetErrorResponseAsync();

                return;
            }
            if (user == "help")
            {
                await ReplyAsync(
                    "Usage: `.fm 'lastfm username/discord user'` \n" +
                    "You can set your default user and your display mode through the `.fmset 'username' 'embedfull/embedmini/textfull/textmini'` command.");

                this._logger.LogCommandUsed(Context.Guild?.Id, Context.Channel.Id, Context.User.Id, Context.Message.Content);
                return;
            }

            try
            {
                string lastFMUserName = userSettings.UserNameLastFM;
                bool   self           = true;

                if (user != null)
                {
                    if (await _lastFmService.LastFMUserExistsAsync(user))
                    {
                        lastFMUserName = user;
                        self           = false;
                    }
                    else if (!_guildService.CheckIfDM(Context))
                    {
                        IGuildUser guildUser = await _guildService.FindUserFromGuildAsync(Context, user);

                        if (guildUser != null)
                        {
                            User guildUserLastFM = await _userService.GetUserSettingsAsync(guildUser);

                            if (guildUserLastFM?.UserNameLastFM != null)
                            {
                                lastFMUserName = guildUserLastFM.UserNameLastFM;
                                self           = false;
                            }
                        }
                    }
                }


                PageResponse <LastTrack> tracks = await _lastFmService.GetRecentScrobblesAsync(lastFMUserName);

                if (tracks?.Any() != true)
                {
                    await NoScrobblesErrorResponseFoundAsync();

                    return;
                }

                LastResponse <LastUser> userinfo = await _lastFmService.GetUserInfoAsync(lastFMUserName);

                LastTrack currentTrack = tracks.Content[0];
                LastTrack lastTrack    = tracks.Content[1];

                const string nullText = "[undefined]";

                string trackName  = currentTrack.Name;
                string artistName = currentTrack.ArtistName;
                string albumName  = string.IsNullOrWhiteSpace(currentTrack.AlbumName) ? nullText : currentTrack.AlbumName;

                string lastTrackName       = lastTrack.Name;
                string lastTrackArtistName = lastTrack.ArtistName;
                string lastTrackAlbumName  = string.IsNullOrWhiteSpace(lastTrack.AlbumName) ? nullText : lastTrack.AlbumName;

                int playCount = userinfo.Content.Playcount;

                switch (userSettings.ChartType)
                {
                case ChartType.textmini:
                    await Context.Channel.SendMessageAsync(await _userService.GetUserTitleAsync(Context)
                                                           + "\n**Current** - "
                                                           + artistName
                                                           + " - "
                                                           + trackName
                                                           + " ["
                                                           + albumName
                                                           + "]\n<https://www.last.fm/user/"
                                                           + userSettings.UserNameLastFM
                                                           + ">\n"
                                                           + userSettings.UserNameLastFM
                                                           + "'s total scrobbles: "
                                                           + playCount.ToString("N0"));

                    break;

                case ChartType.textfull:
                    await Context.Channel.SendMessageAsync(await _userService.GetUserTitleAsync(Context)
                                                           + "\n**Current** - "
                                                           + artistName
                                                           + " - "
                                                           + trackName
                                                           + " ["
                                                           + albumName
                                                           + "]\n**Previous** - "
                                                           + lastTrackArtistName
                                                           + " - "
                                                           + lastTrackName
                                                           + " ["
                                                           + lastTrackAlbumName
                                                           + "]\n<https://www.last.fm/user/"
                                                           + userSettings.UserNameLastFM
                                                           + ">\n"
                                                           + userSettings.UserNameLastFM
                                                           + "'s total scrobbles: "
                                                           + playCount.ToString("N0"));

                    break;

                default:
                    if (!_guildService.CheckIfDM(Context))
                    {
                        GuildPermissions perms = await _guildService.CheckSufficientPermissionsAsync(Context);

                        if (!perms.EmbedLinks)
                        {
                            await ReplyAsync("Insufficient permissions, I need to the 'Embed links' permission to show you your scrobbles.");

                            break;
                        }
                    }

                    var userTitle = await _userService.GetUserTitleAsync(Context);

                    this._embed.AddField(
                        $"Current: {tracks.Content[0].Name}",
                        $"By **{tracks.Content[0].ArtistName}**" + (string.IsNullOrEmpty(tracks.Content[0].AlbumName) ? "" : $" | {tracks.Content[0].AlbumName}"));

                    if (userSettings.ChartType == ChartType.embedfull)
                    {
                        this._embedAuthor.WithName("Last tracks for " + userTitle);
                        this._embed.AddField(
                            $"Previous: {tracks.Content[1].Name}",
                            $"By **{tracks.Content[1].ArtistName}**" + (string.IsNullOrEmpty(tracks.Content[1].AlbumName) ? "" : $" | {tracks.Content[1].AlbumName}"));
                    }
                    else
                    {
                        this._embedAuthor.WithName("Last track for " + userTitle);
                    }

                    this._embed.WithTitle(tracks.Content[0].IsNowPlaying == true
                            ? "*Now playing*"
                            : $"Last scrobble {tracks.Content[0].TimePlayed?.ToString("g")}");

                    this._embedAuthor.WithIconUrl(Context.User.GetAvatarUrl());
                    this._embed.WithAuthor(this._embedAuthor);
                    this._embed.WithUrl("https://www.last.fm/user/" + lastFMUserName);

                    LastImageSet AlbumImages = await _lastFmService.GetAlbumImagesAsync(currentTrack.ArtistName, currentTrack.AlbumName);

                    if (AlbumImages?.Medium != null)
                    {
                        this._embed.WithThumbnailUrl(AlbumImages.Medium.ToString());
                    }

                    this._embedFooter.WithText($"{userinfo.Content.Name} has {userinfo.Content.Playcount} scrobbles.");
                    this._embed.WithFooter(this._embedFooter);

                    this._embed.WithColor(Constants.LastFMColorRed);
                    await ReplyAsync("", false, this._embed.Build());

                    break;
                }
                this._logger.LogCommandUsed(Context.Guild?.Id, Context.Channel.Id, Context.User.Id, Context.Message.Content);
            }
            catch (Exception e)
            {
                _logger.LogError(e.Message, Context.Message.Content, Context.User.Username, Context.Guild?.Name, Context.Guild?.Id);
                await ReplyAsync("Unable to show Last.FM info due to an internal error. Try scrobbling something then use the command again.");
            }
        }
Exemple #3
0
        public async Task fmfriendssetAsync([Summary("Friend names")] params string[] friends)
        {
            User userSettings = await _userService.GetUserSettingsAsync(Context.User).ConfigureAwait(false);

            if (userSettings?.UserNameLastFM == null)
            {
                await UsernameNotSetErrorResponseAsync();

                return;
            }

            try
            {
                string SelfID = Context.Message.Author.Id.ToString();

                List <string> friendList         = new List <string>();
                List <string> friendNotFoundList = new List <string>();

                int friendcount = 0;

                List <Friend> existingFriends = await _friendsService.GetFMFriendsAsync(Context.User).ConfigureAwait(false);

                if (existingFriends.Count + friends.Length > 10)
                {
                    await ReplyAsync("Sorry, but you can't have more then 10 friends.").ConfigureAwait(false);

                    return;
                }

                foreach (string friend in friends)
                {
                    if (existingFriends?.Where(w => w.LastFMUserName != null).Select(s => s.LastFMUserName.ToLower()).Contains(friend.ToLower()) != true)
                    {
                        if (!_guildService.CheckIfDM(Context))
                        {
                            IGuildUser friendUser = await _guildService.FindUserFromGuildAsync(Context, friend).ConfigureAwait(false);

                            if (friendUser != null)
                            {
                                User friendUserSettings = await _userService.GetUserSettingsAsync(friendUser).ConfigureAwait(false);

                                if (friendUserSettings == null || friendUserSettings.UserNameLastFM == null)
                                {
                                    if (await _lastFmService.LastFMUserExistsAsync(friend).ConfigureAwait(false))
                                    {
                                        await _friendsService.AddLastFMFriendAsync(Context.User.Id.ToString(), friend).ConfigureAwait(false);

                                        friendcount++;
                                    }
                                    else
                                    {
                                        friendNotFoundList.Add(friend);
                                    }
                                }
                                else
                                {
                                    await _friendsService.AddDiscordFriendAsync(Context.User.Id.ToString(), friendUser.Id.ToString()).ConfigureAwait(false);

                                    friendcount++;
                                }
                            }
                            else
                            {
                                if (await _lastFmService.LastFMUserExistsAsync(friend).ConfigureAwait(false))
                                {
                                    await _friendsService.AddLastFMFriendAsync(Context.User.Id.ToString(), friend).ConfigureAwait(false);

                                    friendcount++;
                                }
                                else
                                {
                                    friendNotFoundList.Add(friend);
                                }
                            }
                        }
                        else
                        {
                            if (await _lastFmService.LastFMUserExistsAsync(friend).ConfigureAwait(false))
                            {
                                await _friendsService.AddLastFMFriendAsync(Context.User.Id.ToString(), friend).ConfigureAwait(false);

                                friendcount++;
                            }
                            else
                            {
                                friendNotFoundList.Add(friend);
                            }
                        }
                    }
                }

                if (friendcount > 1)
                {
                    await ReplyAsync("Succesfully added " + friendcount + " friends.").ConfigureAwait(false);
                }
                else if (friendcount == 1)
                {
                    await ReplyAsync("Succesfully added a friend.").ConfigureAwait(false);
                }

                if (friendNotFoundList.Count > 0)
                {
                    if (friendNotFoundList.Count > 1)
                    {
                        await ReplyAsync("Could not find " + friendNotFoundList.Count + " friends. Please ensure that you spelled their names correctly.").ConfigureAwait(false);
                    }
                    else
                    {
                        await ReplyAsync("Could not find 1 friend. Please ensure that you spelled the name correctly.").ConfigureAwait(false);
                    }
                }
                this._logger.LogCommandUsed(Context.Guild?.Id, Context.Channel.Id, Context.User.Id, Context.Message.Content);
            }
            catch (Exception e)
            {
                _logger.LogError(e.Message, Context.Message.Content, Context.User.Username, Context.Guild?.Name, Context.Guild?.Id);

                int friendcount = friends.Length;

                if (friendcount > 1)
                {
                    await ReplyAsync("Unable to add " + friendcount + " friends due to an internal error.").ConfigureAwait(false);
                }
                else
                {
                    await ReplyAsync("Unable to add a friend due to an internal error.").ConfigureAwait(false);
                }
            }
        }
Exemple #4
0
        public async Task fmfullhelpAsync()
        {
            string prefix = ConfigData.Data.CommandPrefix;

            ISelfUser SelfUser = Context.Client.CurrentUser;

            string description = null;
            int    length      = 0;

            EmbedBuilder builder = new EmbedBuilder();

            foreach (ModuleInfo module in _service.Modules.OrderByDescending(o => o.Commands.Count()).Where(w => !w.Name.Contains("SecretCommands") && !w.Name.Contains("OwnerCommands") && !w.Name.Contains("AdminCommands") && !w.Name.Contains("GuildCommands")))
            {
                foreach (CommandInfo cmd in module.Commands)
                {
                    PreconditionResult result = await cmd.CheckPreconditionsAsync(Context);

                    if (result.IsSuccess)
                    {
                        if (!string.IsNullOrWhiteSpace(cmd.Summary))
                        {
                            description += $"{prefix}{cmd.Aliases.First()} - {cmd.Summary}\n";
                        }
                        else
                        {
                            description += $"{prefix}{cmd.Aliases.First()}\n";
                        }
                    }
                }


                if (description.Length < 1024)
                {
                    builder.AddField
                        (module.Name + (module.Summary != null ? " - " + module.Summary : ""),
                        description != null ? description : "");
                }


                length     += description.Length;
                description = null;

                if (length < 1990)
                {
                    await Context.User.SendMessageAsync("", false, builder.Build()).ConfigureAwait(false);

                    builder = new EmbedBuilder();
                    length  = 0;
                }
            }


            builder = new EmbedBuilder
            {
                Title = "Additional information",
            };

            builder.AddField("Quick tips",
                             "- Be sure to use 'help' after a command name to see the parameters. \n" +
                             "- Chart sizes range from 3x3 to 10x10 \n" +
                             "- Most commands have no required parameters");


            builder.AddField("Setting your username",
                             "Use `" + prefix + "fmset 'username' 'embedfull/embedmini/textfull/textmini'` to set your global LastFM username. " +
                             "The last parameter means the mode that your embed will be");


            builder.AddField("Making album charts",
                             "`" + prefix + "fmchart '3x3-10x10' 'weekly/monthly/yearly/overall' 'notitles/titles' 'user'`");


            builder.AddField("Making artist charts",
                             "`" + prefix + "fmartistchart '3x3-10x10' 'weekly/monthly/yearly/overall' 'notitles/titles' 'user'`");


            builder.AddField("Setting the default server settings",
                             "Please note that server defaults are a planned feature. \n" +
                             "Only users with the 'Ban Members' permission or admins can use this command. \n" +
                             "`" + prefix + "fmserverset 'embedfull/embedmini/textfull/textmini' 'Weekly/Monthly/Yearly/AllTime'`");

            builder.WithFooter("Still need help? Join the FMBot Discord Server: https://discord.gg/srmpCaa");

            await Context.User.SendMessageAsync("", false, builder.Build()).ConfigureAwait(false);

            if (!guildService.CheckIfDM(Context))
            {
                await Context.Channel.SendMessageAsync("Check your DMs!").ConfigureAwait(false);
            }
        }