goto almost done, enabled experimental flags for C#7 preview support

This commit is contained in:
Master Kwoth 2016-04-18 01:50:01 +02:00
parent 76592c99c2
commit 0d6000daed
4 changed files with 88 additions and 17 deletions

View File

@ -175,6 +175,14 @@ namespace NadekoBot.Modules.Music.Classes
} }
} }
public void AddSong(Song s, int index) {
if (s == null)
throw new ArgumentNullException(nameof(s));
lock (playlistLock) {
playlist.Insert(index, s);
}
}
public void RemoveSong(Song s) public void RemoveSong(Song s)
{ {
if (s == null) if (s == null)

View File

@ -43,11 +43,30 @@ namespace NadekoBot.Modules.Music.Classes
private ulong bytesSent { get; set; } = 0; private ulong bytesSent { get; set; } = 0;
public bool PrintStatusMessage { get; set; } = true;
private int skipTo = 0;
public int SkipTo {
get { return SkipTo; }
set {
skipTo = value;
bytesSent = (ulong)skipTo * 3840 * 50;
}
}
private Song(SongInfo songInfo) private Song(SongInfo songInfo)
{ {
this.SongInfo = songInfo; this.SongInfo = songInfo;
} }
public Song Clone()
{
var s = new Song(SongInfo);
s.MusicPlayer = MusicPlayer;
s.State = StreamState.Queued;
return s;
}
private Task BufferSong(CancellationToken cancelToken) => private Task BufferSong(CancellationToken cancelToken) =>
Task.Factory.StartNew(async () => Task.Factory.StartNew(async () =>
{ {
@ -57,7 +76,7 @@ namespace NadekoBot.Modules.Music.Classes
p = Process.Start(new ProcessStartInfo p = Process.Start(new ProcessStartInfo
{ {
FileName = "ffmpeg", FileName = "ffmpeg",
Arguments = $"-i {SongInfo.Uri} -f s16le -ar 48000 -ac 2 pipe:1 -loglevel quiet", Arguments = $"-ss {skipTo} -i {SongInfo.Uri} -f s16le -ar 48000 -ac 2 pipe:1 -loglevel quiet",
UseShellExecute = false, UseShellExecute = false,
RedirectStandardOutput = true, RedirectStandardOutput = true,
RedirectStandardError = false, RedirectStandardError = false,

View File

@ -1,8 +1,8 @@
using Discord; using Discord;
using Discord.Commands; using Discord.Commands;
using Discord.Modules; using Discord.Modules;
using NadekoBot.DataModels;
using NadekoBot.Classes; using NadekoBot.Classes;
using NadekoBot.DataModels;
using NadekoBot.Extensions; using NadekoBot.Extensions;
using NadekoBot.Modules.Music.Classes; using NadekoBot.Modules.Music.Classes;
using NadekoBot.Modules.Permissions.Classes; using NadekoBot.Modules.Permissions.Classes;
@ -534,6 +534,42 @@ namespace NadekoBot.Modules.Music
} }
} }
}); });
cgb.CreateCommand("goto")
.Description("Goes to a specific time in seconds in a song.")
.Parameter("time")
.Do(async e =>
{
var skipToStr = e.GetArg("time")?.Trim();
MusicPlayer musicPlayer;
if (!MusicPlayers.TryGetValue(e.Server, out musicPlayer))
return;
int skipTo;
if (!int.TryParse(skipToStr, out skipTo) || skipTo < 0)
return;
var currentSong = musicPlayer.CurrentSong;
if (currentSong == null)
return;
//currentSong.PrintStatusMessage = false;
var gotoSong = currentSong.Clone();
gotoSong.SkipTo = skipTo;
musicPlayer.AddSong(gotoSong, 0);
musicPlayer.Next();
var minutes = (skipTo / 60).ToString();
var seconds = (skipTo % 60).ToString();
if (minutes.Length == 1)
minutes = "0" + minutes;
if (seconds.Length == 1)
seconds = "0" + seconds;
await e.Channel.SendMessage($"`Skipped to {minutes}:{seconds}`");
});
}); });
} }
@ -561,27 +597,35 @@ namespace NadekoBot.Modules.Music
Message lastFinishedMessage = null; Message lastFinishedMessage = null;
mp.OnCompleted += async (s, song) => mp.OnCompleted += async (s, song) =>
{ {
try if (song.PrintStatusMessage)
{ {
if (lastFinishedMessage != null) try
await lastFinishedMessage.Delete(); {
if (playingMessage != null) if (lastFinishedMessage != null)
await playingMessage.Delete(); await lastFinishedMessage.Delete();
lastFinishedMessage = await textCh.SendMessage($"🎵`Finished`{song.PrettyName}"); if (playingMessage != null)
await playingMessage.Delete();
lastFinishedMessage = await textCh.SendMessage($"🎵`Finished`{song.PrettyName}");
}
catch { }
} }
catch { }
}; };
mp.OnStarted += async (s, song) => mp.OnStarted += async (s, song) =>
{ {
var sender = s as MusicPlayer; if (song.PrintStatusMessage)
if (sender == null)
return;
try
{ {
var msgTxt = $"🎵`Playing`{song.PrettyName} `Vol: {(int)(sender.Volume * 100)}%`"; var sender = s as MusicPlayer;
playingMessage = await textCh.SendMessage(msgTxt); if (sender == null)
return;
try
{
var msgTxt = $"🎵`Playing`{song.PrettyName} `Vol: {(int)(sender.Volume * 100)}%`";
playingMessage = await textCh.SendMessage(msgTxt);
}
catch { }
} }
catch { }
}; };
return mp; return mp;
}); });

View File

@ -40,7 +40,7 @@
<DebugType>full</DebugType> <DebugType>full</DebugType>
<Optimize>false</Optimize> <Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath> <OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants> <DefineConstants>TRACE;DEBUG;__DEMO__,__DEMO_EXPERIMENTAL__</DefineConstants>
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
<Prefer32Bit>true</Prefer32Bit> <Prefer32Bit>true</Prefer32Bit>