goto almost done, enabled experimental flags for C#7 preview support
This commit is contained in:
parent
76592c99c2
commit
0d6000daed
@ -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)
|
||||
{
|
||||
if (s == null)
|
||||
|
@ -43,11 +43,30 @@ namespace NadekoBot.Modules.Music.Classes
|
||||
|
||||
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)
|
||||
{
|
||||
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) =>
|
||||
Task.Factory.StartNew(async () =>
|
||||
{
|
||||
@ -57,7 +76,7 @@ namespace NadekoBot.Modules.Music.Classes
|
||||
p = Process.Start(new ProcessStartInfo
|
||||
{
|
||||
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,
|
||||
RedirectStandardOutput = true,
|
||||
RedirectStandardError = false,
|
||||
|
@ -1,8 +1,8 @@
|
||||
using Discord;
|
||||
using Discord.Commands;
|
||||
using Discord.Modules;
|
||||
using NadekoBot.DataModels;
|
||||
using NadekoBot.Classes;
|
||||
using NadekoBot.DataModels;
|
||||
using NadekoBot.Extensions;
|
||||
using NadekoBot.Modules.Music.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}`");
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@ -560,6 +596,8 @@ namespace NadekoBot.Modules.Music
|
||||
Message playingMessage = null;
|
||||
Message lastFinishedMessage = null;
|
||||
mp.OnCompleted += async (s, song) =>
|
||||
{
|
||||
if (song.PrintStatusMessage)
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -570,18 +608,24 @@ namespace NadekoBot.Modules.Music
|
||||
lastFinishedMessage = await textCh.SendMessage($"🎵`Finished`{song.PrettyName}");
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
};
|
||||
mp.OnStarted += async (s, song) =>
|
||||
{
|
||||
if (song.PrintStatusMessage)
|
||||
{
|
||||
var sender = s as MusicPlayer;
|
||||
if (sender == null)
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
var msgTxt = $"🎵`Playing`{song.PrettyName} `Vol: {(int)(sender.Volume * 100)}%`";
|
||||
playingMessage = await textCh.SendMessage(msgTxt);
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
};
|
||||
return mp;
|
||||
});
|
||||
|
@ -40,7 +40,7 @@
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<DefineConstants>TRACE;DEBUG;__DEMO__,__DEMO_EXPERIMENTAL__</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<Prefer32Bit>true</Prefer32Bit>
|
||||
|
Loading…
Reference in New Issue
Block a user