Ejemplo n.º 1
0
        /// <summary>
        /// Triggers a search into the history DB to play the last song
        /// </summary>
        /// <param name="form">The main form</param>
        /// <param name="hidb">The history database</param>
        /// <param name="db">The queue database</param>
        public static async void Playprevious(MainWindow form, LiteDatabase hidb, LiteDatabase db, DiscordSocketClient discordclient, Config conf)
        {
            // Search for all songs in the hisotry
            var historydb = hidb.GetCollection <History>("History");
            var results   = historydb.FindAll();
            var client    = new YoutubeClient();

            YoutubeExplode.Videos.Video video = null;
            // Attempt to get the video info of the last one
            for (int attempts = 0; attempts < 3; attempts++)
            {
                try
                {
                    video = await client.Videos.GetAsync(results.Last().YoutubeId);

                    break;
                }
                catch { }
                Thread.Sleep(2000);
            }
            // Create a temp file to download it to and send it to the video player
            if (video != null)
            {
                string tempfile = FileFunctions.CreateTmpFile();
                Song   temp     = new Song
                {
                    Priority          = 0,
                    RequesterId       = 0,
                    RequesterUsername = "******",
                    YoutubeId         = results.Last().YoutubeId,
                    Title             = video.Title,
                    Description       = await SongRequest.GetDescriptionAsync(video.Title),
                    File     = tempfile,
                    Duration = video.Duration.ToString(),
                    Approved = true,
                    Id       = 999999999
                };
                _ = TriggerqueueAsync(temp, form, hidb, db, discordclient, conf);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Function to add a song to the queue from Manual requests
        /// </summary>
        /// <param name="url">The URL to add</param>
        /// <param name="form">The main form running</param>
        /// <param name="hidb">The history DB</param>
        /// <param name="db">The queue DB</param>
        public static async void ManualRequest(string url, MainWindow form, LiteDatabase hidb, LiteDatabase db, DiscordSocketClient discordclient, Config conf)
        {
            // Parse the ID
            var client = new YoutubeClient();

            YoutubeExplode.Videos.Video video = null;
            // Attempt to get the video information
            for (int attempts = 0; attempts < 3; attempts++)
            {
                try
                {
                    video = await client.Videos.GetAsync(url);

                    break;
                }
                catch { }
                Thread.Sleep(2000);
            }
            // If we found it add it to the queue
            if (video != null)
            {
                string tempfile = FileFunctions.CreateTmpFile();
                Song   temp     = new Song
                {
                    Priority          = 0,
                    RequesterId       = 0,
                    RequesterUsername = "******",
                    YoutubeId         = url,
                    Title             = video.Title,
                    Description       = await SongRequest.GetDescriptionAsync(video.Title),
                    File     = tempfile,
                    Duration = video.Duration.ToString(),
                    Approved = true,
                    Id       = 999999999
                };
                _ = TriggerqueueAsync(temp, form, hidb, db, discordclient, conf);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Request a song and add it to the relevant data
        /// </summary>
        /// <param name="message">The socketmessage to parse</param>
        /// <param name="hidb">The History DB</param>
        /// <param name="db">The Queue DB</param>
        /// <param name="usrdb">The User DB</param>
        /// <param name="priority">The priority to add the song at</param>
        /// <param name="username">The username to impersonate</param>
        /// <param name="roles">The list of roles to check against for mods</param>
        /// <returns>Returns the return message</returns>
        public static async System.Threading.Tasks.Task <string> RequestSongAsync(Config conf, DiscordSocketClient discordclient, SocketMessage message, LiteDatabase hidb, LiteDatabase db, LiteDatabase usrdb, List <string> roles, int priority = 0, string username = null)
        {
            try
            {
                // Try to parse the string
                var  id       = message.Content.Split().ToList()[1];
                var  client   = new YoutubeClient();
                bool approved = false;
                // Check if the user is a mod, if they are automatically approve the video
                if (DataFunctions.IsMod(message, roles))
                {
                    approved = true;
                }
                // Check if the user has already requested a song in the queue
                var queuedb          = db.GetCollection <Song>("Queue");
                var resultsrequested = queuedb.Find(x => x.RequesterId == message.Author.Id);
                if (DataFunctions.IsMod(message, roles) == false && resultsrequested.ToList().Count > 0)
                {
                    return("You have already requested a song");
                }
                // Check if the song is revoked for bad words
                if (DataFunctions.IsBadSong(id, hidb))
                {
                    return("The song you requested was removed for bad language");
                }
                // Check if the song has already been played tonight but isin't in the queue
                var historydb = hidb.GetCollection <History>("History");
                var results   = historydb.Find(x => x.YoutubeId.StartsWith(id) && x.Played == true);
                if (results.ToList().Count > 0)
                {
                    return("Song has already been played");
                }
                // Check if the song is already in the queue
                var resultsq = queuedb.Find(x => x.YoutubeId.StartsWith(id));
                if (resultsq.ToList().Count > 0)
                {
                    return("Song has already been requested");
                }
                // Get the video data from youtube
                YoutubeExplode.Videos.Video video = null;
                for (int attempts = 0; attempts < 3; attempts++)
                {
                    try
                    {
                        video = await client.Videos.GetAsync(id);
                        await GetDescriptionAsync(video.Title);

                        break;
                    }
                    catch { }
                    Thread.Sleep(2000);
                }
                // If the video actually returned correctly
                if (video != null)
                {
                    // Make sure the song is from Siivagunner
                    if (video.Author.Title.ToLower() == "siivagunner")
                    {
                        // Create a temp file to store the song in
                        string tempfile = FileFunctions.CreateTmpFile();
                        // Set the username to either the users or impersonate
                        string tempuser = message.Author.Username;
                        if (username != null)
                        {
                            tempuser = username;
                        }
                        ulong chan = 0;
                        foreach (var channel in discordclient.GetGuild(Convert.ToUInt64(conf.Guild)).Channels)
                        {
                            if (channel.Name.ToLower() == conf.ApprovalChannel.ToLower())
                            {
                                chan = channel.Id;
                                break;
                            }
                        }
                        var toEmebed = new EmbedBuilder();
                        toEmebed.WithTitle("Song Request");
                        toEmebed.WithColor(Color.Red);
                        string description = await GetDescriptionAsync(video.Title);

                        string longembed = "Requested by: " + tempuser + "\nSong Title: " + video.Title + "\nhttps://www.youtube.com/watch?v=" + id + "\n" + description;
                        toEmebed.WithDescription(longembed.Truncate(1950));

                        var messageid = await discordclient.GetGuild(Convert.ToUInt64(conf.Guild)).GetTextChannel(chan).SendMessageAsync("", false, toEmebed.Build());

                        _ = messageid.AddReactionsAsync(new[] { new Emoji("👍"), new Emoji("👎") });


                        // Generate the template data for the song to add
                        var newsong = new Song
                        {
                            RequesterId       = message.Author.Id,
                            RequesterUsername = tempuser,
                            Duration          = video.Duration.ToString(),
                            Title             = video.Title,
                            File            = tempfile,
                            YoutubeId       = id,
                            Priority        = priority,
                            Description     = description,
                            Approved        = approved,
                            ApprovalMessage = messageid.Id
                        };
                        // Insert the song into the database
                        queuedb.Insert(newsong);
                        // Check if the user had already requested something
                        if (DataFunctions.AlreadyRequested(message.Author, db) == false)
                        {
                            // Find the user and update their data to now have already requested something
                            var userdb     = usrdb.GetCollection <Users>("Users");
                            var resultsusr = userdb.Find(x => x.DiscordUserId == message.Author.Id);
                            if (resultsusr.Count() >= 1)
                            {
                                Users usr = new Users();
                                usr = resultsusr.First();
                                usr.AlreadyRequested = true;
                                userdb.Update(usr);
                            }
                        }
                        // If the song was already approved if they are a mod just add it to the queue
                        if (approved == true)
                        {
                            return("Your song has now been added to the queue");
                        }
                        else
                        {
                            // If they are not a mod tell them we need to approve it
                            return("Your song has now been added to the queue, it needs to be approved by a mod");
                        }
                    }
                    else
                    {
                        // Tell them they messed up cause its not owned by siivagunner
                        return("This song is not owned by Siivagunner");
                    }
                }
                // Return that we had an error
                else
                {
                    return("An error has occured please try again.");
                }
            }
            catch
            {
                // Safety response just return we had an error
                return("An error has occured please try again.");
            }
        }