Exemplo n.º 1
0
        private static async Task StartPlay(DUser duser, bool Next = false)
        {
            await DiscordUtils.SendBotMessage(Utils.Replace(Messages.AudioStartedPlaying, "~1", duser.VoiceChannel.Name), duser);

            await duser.VNCon.SendSpeakingAsync(true);

            Video v = MusicBot.FirstPlay();

            if (Next)
            {
                v = MusicBot.NextQueue();
            }
            Random rd        = new Random();
            int    SpecialID = rd.Next(12, 123123);
            await DiscordUtils.SendBotMessage(Utils.Replace(Utils.Replace(Messages.AudioMusicNextSongInQueue, "~2", DUtils.GetMusicURL(v)), "~1", v.Title), duser);

            await MusicBot.VoiceStream(duser.VNCon, v, SpecialID);

            while (MusicBot.Queue.ContainsKey(1))
            {
                Utils.Debug((object)"MusicBot, Playing next song!");
                await Task.Delay(1500);

                v = MusicBot.NextQueue();
                await DiscordUtils.SendBotMessage(Utils.Replace(Utils.Replace(Messages.AudioMusicNextSongInQueue, "~2", DUtils.GetMusicURL(v)), "~1", v.Title), duser);

                await MusicBot.VoiceStream(duser.VNCon, v, SpecialID);
            }
            MusicBot.ClearQueue();
            await DiscordUtils.SendBotMessage(Messages.AudioMusicQueueEnded, duser);
        }
Exemplo n.º 2
0
        public async Task CMDVolume(CommandContext ctx, [RemainingText, Description("Volume. (1 = 100%)")] float V)
        {
            await TryDelete(ctx);

            MusicBot.ChangeVolume(V);
            await DiscordUtils.SendBotMessage(Messages.AudioVolumeChange, ctx.Message.Channel, user : ctx.User);
        }
Exemplo n.º 3
0
        public async Task Play(CommandContext ctx, [RemainingText, Description("Full youtube URL.")] string YoutubeURL)
        {
            if (!YoutubeURL.ToLower().StartsWith("http://"))
            {
                YoutubeURL = "https://" + YoutubeURL;
            }

            await TryDelete(ctx);

            string filename = "";
            Video  vid      = null;

            try
            {
                YouTube youtube = YouTube.Default;
                vid = youtube.GetVideo(YoutubeURL);
                if (!Directory.Exists("Bot"))
                {
                    Directory.CreateDirectory("Bot");
                }

                filename = MusicBot.CreatePathFromVid(vid);
                if (!File.Exists(filename))
                {
                    await DiscordUtils.SendBotMessage(Messages.AudioDownloading, ctx.Message.Channel, user : ctx.User);

                    string filenameNoMP3 = @Directory.GetCurrentDirectory() + "\\Bot\\" + vid.FullName + ".Temp";
                    File.WriteAllBytes(filenameNoMP3, vid.GetBytes());
                    var inputFile = new MediaFile {
                        Filename = filenameNoMP3
                    };
                    var outputFile = new MediaFile {
                        Filename = filename
                    };

                    using (var engine = new Engine()) {
                        engine.GetMetadata(inputFile);
                        engine.Convert(inputFile, outputFile);
                    }
                    File.Delete(filenameNoMP3);
                }
            }
            catch (Exception e)
            {
                await ctx.RespondAsync("Error: " + e.Message);

                await Task.Delay(1);

                return;
            }
            if (vid != null)
            {
                MusicBot.AddToQueue(vid);
            }
            await DiscordUtils.SendBotMessage(Utils.Replace(Messages.AudioMusicAddedToQueue, "~1", vid.Title), ctx.Message.Channel, user : ctx.User);

            await MusicBot.Play(ctx);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Simply gets the queue for the current server/guild
        /// </summary>
        /// <param name="duser"> Args = Volume ( 1 = 100%, 0.1 = 10%, 2 = 200%)</param>
        /// <returns></returns>
        public static async Task MusicChangeVolume(DUser duser)
        {
            float V = 0; //Just to set an int

            if (!float.TryParse(duser.Args, out V))
            { //Try parse. If error say it
                await DiscordUtils.SendBotMessage(Messages.StringToNumberError, duser);

                return;
            }
            MusicBot.ChangeVolume(V);
            await DiscordUtils.SendBotMessage(Messages.AudioVolumeChange, duser);
        }
Exemplo n.º 5
0
        public async Task CMDRemove(CommandContext ctx, [RemainingText, Description("Full youtube URL.")] int ID)
        {
            await TryDelete(ctx);

            Video vid  = MusicBot.GetVideo(ID);
            bool  Good = MusicBot.RemoveVideo(ID);

            if (Good && (vid != null))
            {
                await DiscordUtils.SendBotMessage(Utils.Replace(Messages.AudioMusicRemove, "~1", vid.FullName), ctx.Message.Channel, user : ctx.User);
            }
            else
            {
                await DiscordUtils.SendBotMessage(Utils.Replace(Messages.AudioMusicRemoveERROR, "~1", ID + ""), ctx.Message.Channel, user : ctx.User);
            }
        }
Exemplo n.º 6
0
        public static async Task Play(DUser duser, bool Next = false)
        {
            MusicBot.StopPlayingJoined = false;
            VoiceNextClient vnext = duser.VNClient;

            if (vnext == null)
            {
                await DiscordUtils.SendBotMessage("VNext is not enabled or configured.", duser);
            }
            else
            {
                VoiceNextConnection vnc = duser.VNCon;
                if (vnc == null)
                {
                    await DiscordUtils.SendBotMessage(Messages.AudioNotconnectedToServer, duser);

                    await CommandFunctions.MusicJoinCh(duser);

                    await Task.Delay(200);

                    await MusicBot.Play(duser, false);
                }
                else if (Next)
                {
                    MusicBot.ThreadID.Abort();
                    await Task.Delay(1000);

                    MusicBot.ThreadID = new Thread((ThreadStart)(() => MusicBot.StartPlay(duser, false)));
                    MusicBot.ThreadID.Start();
                }
                else if (MusicBot.CurrentPlaying(duser))
                {
                    await DiscordUtils.SendBotMessage(Messages.AudioMusicAlreadyPlaying, duser);
                }
                else
                {
                    MusicBot.ThreadID = new Thread((ThreadStart)(() => MusicBot.StartPlay(duser, false)));
                    MusicBot.ThreadID.Start();
                }
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Removes a song from the music Queue
        /// </summary>
        /// <param name="duser">Args = Queue ID</param>
        /// <returns></returns>
        public static async Task MusicRemoveSong(DUser duser)
        {
            int ID = 0; //Just to set an int

            if (!Int32.TryParse(duser.Args, out ID))
            { //Try parse. If error say it
                await DiscordUtils.SendBotMessage(Messages.StringToNumberError, duser);

                return;
            }
            Video vid  = MusicBot.GetVideo(ID);
            bool  Good = MusicBot.RemoveVideo(ID);

            if (Good && (vid != null))
            {
                await DiscordUtils.SendBotMessage(Utils.Replace(Messages.AudioMusicRemove, "~1", vid.FullName), duser);
            }
            else
            {
                await DiscordUtils.SendBotMessage(Utils.Replace(Messages.AudioMusicRemoveERROR, "~1", ID + ""), duser);
            }
        }
Exemplo n.º 8
0
        public async Task CMDHowLong(CommandContext ctx)
        {
            await TryDelete(ctx);

            await DiscordUtils.SendBotMessage(Utils.Replace(Messages.AudioMusicProcentLeft, "~1", MusicBot.CurrentPlayingProcent()), ctx.Message.Channel, user : ctx.User);
        }
Exemplo n.º 9
0
 /// <summary>
 /// Simply gets the queue for the current server/guild
 /// </summary>
 /// <param name="duser"></param>
 /// <returns></returns>
 public static async Task MusicProcentLeft(DUser duser)
 {
     await DiscordUtils.SendBotMessage(Utils.Replace(Messages.AudioMusicProcentLeft, "~1", MusicBot.CurrentPlayingProcent()), duser);
 }
Exemplo n.º 10
0
 /// <summary>
 /// Simply gets the queue for the current server/guild
 /// </summary>
 /// <param name="duser"></param>
 /// <returns></returns>
 public static async Task MusicContinueCrash(DUser duser)
 {
     await MusicBot.Play(duser);
 }
Exemplo n.º 11
0
 /// <summary>
 /// Simply gets the queue for the current server/guild
 /// </summary>
 /// <param name="duser"></param>
 /// <returns></returns>
 public static async Task MusicQueue(DUser duser)
 {
     await DiscordUtils.SendBotMessage(MusicBot.StringList(duser), duser);
 }
Exemplo n.º 12
0
 /// <summary>
 /// Simply Skips to the next song in the Queue
 /// </summary>
 /// <param name="duser"></param>
 /// <returns></returns>
 public static async Task MusicSkip(DUser duser)
 {
     MusicBot.NextSong();
     await Task.Delay(1);
 }
Exemplo n.º 13
0
        /// <summary>
        /// Start playing music
        /// </summary>
        /// <param name="duser">Args = YoutubeURL</param>
        /// <returns></returns>
        public static async Task MusicPlay(DUser duser)
        {
            String YoutubeURL = duser.Args;

            if (!YoutubeURL.ToLower().StartsWith("https://"))
            {
                YoutubeURL = "https://" + YoutubeURL;
            }
            string filename = "";
            Video  vid      = null;

            try
            {
                YouTube youtube = YouTube.Default;
                vid = youtube.GetVideo(YoutubeURL);
                if (!Directory.Exists(Config.VideoDir))
                {
                    Directory.CreateDirectory(Config.VideoDir);
                }

                filename = MusicBot.CreatePathFromVid(vid);
                if (!File.Exists(filename))
                {
                    await DiscordUtils.SendBotMessage(Messages.AudioDownloading, duser);

                    string filenameNoMP3 = @Config.VideoDir + Utils.RemoveSpecialCharacters(vid.FullName) + ".Temp";
                    Utils.Debug("Vid UrL: " + YoutubeURL);
                    Utils.Debug("Vid Uri: " + await vid.GetUriAsync());
                    File.WriteAllBytes(filenameNoMP3, vid.GetBytes());
                    var inputFile = new MediaFile {
                        Filename = filenameNoMP3
                    };
                    var outputFile = new MediaFile {
                        Filename = filename
                    };

                    using (var engine = new Engine())
                    {
                        engine.GetMetadata(inputFile);
                        engine.Convert(inputFile, outputFile);
                    }
                    File.Delete(filenameNoMP3);
                    DUtils.SetMusicURL(vid, YoutubeURL);
                }
            }
            catch (Exception e)
            {
                Utils.Log(e.Message + " ----- " + e.StackTrace, LogType.Error);
                await DiscordUtils.SendBotMessage("Error: " + e.Message, duser);

                await Task.Delay(1);

                return;
            }
            if (vid != null)
            {
                MusicBot.AddToQueue(vid);
            }
            await DiscordUtils.SendBotMessage(Utils.Replace(Utils.Replace(Messages.AudioMusicAddedToQueue, "~2", YoutubeURL), "~1", vid.Title), duser);

            await MusicBot.Play(duser);
        }
Exemplo n.º 14
0
        public static async Task VoiceStream(VoiceNextConnection vnc, Video vid, int SpecialID)
        {
            MusicBot.ThreadIDD      = SpecialID;
            MusicBot.UsersInChannel = DUtils.GetAmountInVoice(vnc.Channel);
            new Thread((ThreadStart)(() => vnc.VoiceReceived += (AsyncEventHandler <VoiceReceiveEventArgs>)(async e =>
            {
                if (SpecialID != MusicBot.ThreadIDD)
                {
                    Thread.CurrentThread.Abort();
                }
                try
                {
                    if (Config.StopPlayingIfANYsoundIsReceived)
                    {
                        MusicBot.StopPlayingJoined = true;
                    }
                    else
                    {
                        Utils.Debug((object)("Musicbot, Received sounds!!!" + e.User.Username));
                    }
                }
                catch (Exception ex)
                {
                    if (Config.StopPlayingWithNewPlayer)
                    {
                        MusicBot.StopPlayingJoined = true;
                    }
                    if (!ex.Message.Contains("De objectverwijzing is niet op een exemplaar van een object ingesteld.") || !Config.StopPlayingWithNewPlayer)
                    {
                        return;
                    }
                    MusicBot.StopPlayingJoined = true;
                }
                await Task.Delay(1);
            }))).Start();
            Exception exc      = (Exception)null;
            string    filename = MusicBot.CreatePathFromVid(MusicBot.FirstPlay());

            if (!File.Exists(filename))
            {
                Utils.Log(string.Format("File `{0}` does not exist.", (object)filename), LogType.Error);
            }
            else
            {
                Exception obj = null;
                int       num = 0;
                try
                {
                    try
                    {
                        int        SampleRate   = 48000;
                        int        channelCount = 2;
                        WaveFormat OutFormat    = new WaveFormat(SampleRate, 16, channelCount);
                        MediaFoundationResampler resampler;
                        WaveStream mediaStream;
                        try
                        {
                            mediaStream = (WaveStream) new WaveChannel32((WaveStream) new MediaFoundationReader(filename), MusicBot.Volume, 0.0f);
                            WaveStream waveStream = mediaStream;
                            try
                            {
                                MediaFoundationResampler foundationResampler = resampler = new MediaFoundationResampler((IWaveProvider)mediaStream, OutFormat);
                                try
                                {
                                    int m = int.Parse(string.Concat((object)mediaStream.Length));
                                    MusicBot.IntPlayout        = m / 2 + m / 35;
                                    MusicBot.TotalSendBytes    = 0;
                                    resampler.ResamplerQuality = 60;
                                    int    blockSize = OutFormat.AverageBytesPerSecond / 50;
                                    byte[] buffer    = new byte[blockSize];
                                    do
                                    {
                                        int byteCount;
                                        if ((byteCount = resampler.Read(buffer, 0, blockSize)) > 0)
                                        {
                                            while (MusicBot.StopPlayingJoined)
                                            {
                                                Thread.Sleep(100);
                                            }
                                            if (byteCount < blockSize)
                                            {
                                                for (int i = byteCount; i < blockSize; ++i)
                                                {
                                                    buffer[i] = (byte)0;
                                                }
                                            }
                                            MusicBot.TotalSendBytes += buffer.Length;
                                            Utils.Debug((object)("MusicBot, " + (object)MusicBot.TotalSendBytes + "/" + (object)MusicBot.IntPlayout));
                                            if (SpecialID == MusicBot.ThreadIDD)
                                            {
                                                await MusicBot.SendVoiceData(buffer, 20, vnc);
                                            }
                                            else
                                            {
                                                goto label_31;
                                            }
                                        }
                                        else
                                        {
                                            goto label_18;
                                        }
                                    }while (MusicBot.IntPlayout > MusicBot.TotalSendBytes);
                                    Utils.Debug((object)"MusicBot, Finished playing?");
label_18:
                                    buffer = (byte[])null;
                                }
                                finally
                                {
                                    if (foundationResampler != null)
                                    {
                                        foundationResampler.Dispose();
                                    }
                                }
                                foundationResampler = (MediaFoundationResampler)null;
                            }
                            finally
                            {
                                if (waveStream != null)
                                {
                                    waveStream.Dispose();
                                }
                            }
                            waveStream = (WaveStream)null;
                        }
                        catch (Exception ex)
                        {
                            Utils.Log(ex.StackTrace + "\n" + ex.Message, LogType.Error);
                        }
                        resampler   = (MediaFoundationResampler)null;
                        mediaStream = (WaveStream)null;
                        OutFormat   = (WaveFormat)null;
                        goto label_33;
                    }
                    catch (Exception ex)
                    {
                        exc = ex;
                        goto label_33;
                    }
label_31:
                    num = 1;
                }
                catch (Exception ex)
                {
                    obj = ex;
                }
label_33:
                await vnc.SendSpeakingAsync(false);

                Exception obj1 = obj;
                if (obj1 != null)
                {
                    Exception source = obj1 as Exception;
                    if (source == null)
                    {
                        throw obj1;
                    }
                    ExceptionDispatchInfo.Capture(source).Throw();
                }
                if (num == 1)
                {
                    return;
                }
                obj = (Exception)null;
                if (exc == null)
                {
                    return;
                }
                Utils.Log(string.Format("An exception occured during playback: `{0}: {1}`", (object)exc.GetType(), (object)exc.Message), LogType.Error);
            }
        }
Exemplo n.º 15
0
        public async Task CMDqueue(CommandContext ctx)
        {
            await TryDelete(ctx);

            await DiscordUtils.SendBotMessage(MusicBot.StringList(ctx), ctx.Message.Channel, user : ctx.User);
        }
Exemplo n.º 16
0
        public async Task CMDNext(CommandContext ctx)
        {
            await TryDelete(ctx);

            MusicBot.NextSong();
        }
Exemplo n.º 17
0
        public async Task CMDContinue(CommandContext ctx)
        {
            await TryDelete(ctx);

            await MusicBot.Play(ctx);
        }