queuer name added in songs, trimmed to 12 characters.

This commit is contained in:
Master Kwoth 2016-07-07 19:35:56 +02:00
parent 2fda1c0dbb
commit a511d35704
3 changed files with 15 additions and 13 deletions

View File

@ -168,13 +168,14 @@ namespace NadekoBot.Modules.Music.Classes
} }
} }
public void AddSong(Song s) public void AddSong(Song s, string username)
{ {
if (s == null) if (s == null)
throw new ArgumentNullException(nameof(s)); throw new ArgumentNullException(nameof(s));
lock (playlistLock) lock (playlistLock)
{ {
s.MusicPlayer = this; s.MusicPlayer = this;
s.QueuerName = username.TrimTo(10);
playlist.Add(s); playlist.Add(s);
} }
} }

View File

@ -27,8 +27,9 @@ namespace NadekoBot.Modules.Music.Classes
{ {
public StreamState State { get; internal set; } public StreamState State { get; internal set; }
public string PrettyName => public string PrettyName =>
$"**【 {SongInfo.Title.TrimTo(55)} 】**`{(SongInfo.Provider ?? "-")}`"; $"**【 {SongInfo.Title.TrimTo(55)} 】**`{(SongInfo.Provider ?? "-")}` `by {QueuerName}`";
public SongInfo SongInfo { get; } public SongInfo SongInfo { get; }
public string QueuerName { get; set; }
private PoopyBuffer songBuffer { get; } = new PoopyBuffer(NadekoBot.Config.BufferSize); private PoopyBuffer songBuffer { get; } = new PoopyBuffer(NadekoBot.Config.BufferSize);

View File

@ -100,7 +100,7 @@ namespace NadekoBot.Modules.Music
.Parameter("query", ParameterType.Unparsed) .Parameter("query", ParameterType.Unparsed)
.Do(async e => .Do(async e =>
{ {
await QueueSong(e.Channel, e.User.VoiceChannel, e.GetArg("query")).ConfigureAwait(false); await QueueSong(e.User, e.Channel, e.User.VoiceChannel, e.GetArg("query")).ConfigureAwait(false);
if (e.Server.CurrentUser.GetPermissions(e.Channel).ManageMessages) if (e.Server.CurrentUser.GetPermissions(e.Channel).ManageMessages)
{ {
await Task.Delay(10000).ConfigureAwait(false); await Task.Delay(10000).ConfigureAwait(false);
@ -308,7 +308,7 @@ namespace NadekoBot.Modules.Music
{ {
try try
{ {
await QueueSong(e.Channel, e.User.VoiceChannel, id, true).ConfigureAwait(false); await QueueSong(e.User, e.Channel, e.User.VoiceChannel, id, true).ConfigureAwait(false);
} }
catch { } catch { }
} }
@ -327,7 +327,7 @@ namespace NadekoBot.Modules.Music
return; return;
var scvids = JObject.Parse(await SearchHelper.GetResponseStringAsync($"http://api.soundcloud.com/resolve?url={pl}&client_id={NadekoBot.Creds.SoundCloudClientID}"))["tracks"].ToObject<SoundCloudVideo[]>(); var scvids = JObject.Parse(await SearchHelper.GetResponseStringAsync($"http://api.soundcloud.com/resolve?url={pl}&client_id={NadekoBot.Creds.SoundCloudClientID}"))["tracks"].ToObject<SoundCloudVideo[]>();
await QueueSong(e.Channel, e.User.VoiceChannel, scvids[0].TrackLink); await QueueSong(e.User, e.Channel, e.User.VoiceChannel, scvids[0].TrackLink);
MusicPlayer mp; MusicPlayer mp;
if (!MusicPlayers.TryGetValue(e.Server, out mp)) if (!MusicPlayers.TryGetValue(e.Server, out mp))
@ -342,7 +342,7 @@ namespace NadekoBot.Modules.Music
Uri = svideo.StreamLink, Uri = svideo.StreamLink,
ProviderType = MusicType.Normal, ProviderType = MusicType.Normal,
Query = svideo.TrackLink, Query = svideo.TrackLink,
})); }), e.User.Name);
} }
}); });
@ -362,7 +362,7 @@ namespace NadekoBot.Modules.Music
.Where(x => !x.Attributes.HasFlag(FileAttributes.Hidden | FileAttributes.System)); .Where(x => !x.Attributes.HasFlag(FileAttributes.Hidden | FileAttributes.System));
foreach (var file in fileEnum) foreach (var file in fileEnum)
{ {
await QueueSong(e.Channel, e.User.VoiceChannel, file.FullName, true, MusicType.Local).ConfigureAwait(false); await QueueSong(e.User, e.Channel, e.User.VoiceChannel, file.FullName, true, MusicType.Local).ConfigureAwait(false);
} }
await e.Channel.SendMessage("🎵 `Directory queue complete.`").ConfigureAwait(false); await e.Channel.SendMessage("🎵 `Directory queue complete.`").ConfigureAwait(false);
} }
@ -379,7 +379,7 @@ namespace NadekoBot.Modules.Music
await e.Channel.SendMessage("💢 You need to be in a voice channel on this server.\n If you are already in a voice channel, try rejoining it.").ConfigureAwait(false); await e.Channel.SendMessage("💢 You need to be in a voice channel on this server.\n If you are already in a voice channel, try rejoining it.").ConfigureAwait(false);
return; return;
} }
await QueueSong(e.Channel, e.User.VoiceChannel, e.GetArg("radio_link"), musicType: MusicType.Radio).ConfigureAwait(false); await QueueSong(e.User, e.Channel, e.User.VoiceChannel, e.GetArg("radio_link"), musicType: MusicType.Radio).ConfigureAwait(false);
if (e.Server.CurrentUser.GetPermissions(e.Channel).ManageMessages) if (e.Server.CurrentUser.GetPermissions(e.Channel).ManageMessages)
{ {
await Task.Delay(10000).ConfigureAwait(false); await Task.Delay(10000).ConfigureAwait(false);
@ -397,7 +397,7 @@ namespace NadekoBot.Modules.Music
var arg = e.GetArg("path"); var arg = e.GetArg("path");
if (string.IsNullOrWhiteSpace(arg)) if (string.IsNullOrWhiteSpace(arg))
return; return;
await QueueSong(e.Channel, e.User.VoiceChannel, e.GetArg("path"), musicType: MusicType.Local).ConfigureAwait(false); await QueueSong(e.User, e.Channel, e.User.VoiceChannel, e.GetArg("path"), musicType: MusicType.Local).ConfigureAwait(false);
}); });
cgb.CreateCommand("move") cgb.CreateCommand("move")
@ -628,7 +628,7 @@ namespace NadekoBot.Modules.Music
{ {
try try
{ {
await QueueSong(textCh, voiceCh, si.Query, true, (MusicType)si.ProviderType).ConfigureAwait(false); await QueueSong(e.User, textCh, voiceCh, si.Query, true, (MusicType)si.ProviderType).ConfigureAwait(false);
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -740,7 +740,7 @@ namespace NadekoBot.Modules.Music
}); });
} }
public static async Task QueueSong(Channel textCh, Channel voiceCh, string query, bool silent = false, MusicType musicType = MusicType.Normal) public static async Task QueueSong(User queuer, Channel textCh, Channel voiceCh, string query, bool silent = false, MusicType musicType = MusicType.Normal)
{ {
if (voiceCh == null || voiceCh.Server != textCh.Server) if (voiceCh == null || voiceCh.Server != textCh.Server)
{ {
@ -772,7 +772,7 @@ namespace NadekoBot.Modules.Music
lastFinishedMessage = await textCh.SendMessage($"🎵`Finished`{song.PrettyName}").ConfigureAwait(false); lastFinishedMessage = await textCh.SendMessage($"🎵`Finished`{song.PrettyName}").ConfigureAwait(false);
if (mp.Autoplay && mp.Playlist.Count == 0 && song.SongInfo.Provider == "YouTube") if (mp.Autoplay && mp.Playlist.Count == 0 && song.SongInfo.Provider == "YouTube")
{ {
await QueueSong(textCh, voiceCh, await SearchHelper.GetRelatedVideoId(song.SongInfo.Query), silent, musicType).ConfigureAwait(false); await QueueSong(queuer, textCh, voiceCh, await SearchHelper.GetRelatedVideoId(song.SongInfo.Query), silent, musicType).ConfigureAwait(false);
} }
} }
catch (Exception e) catch (Exception e)
@ -801,7 +801,7 @@ namespace NadekoBot.Modules.Music
return mp; return mp;
}); });
var resolvedSong = await Song.ResolveSong(query, musicType).ConfigureAwait(false); var resolvedSong = await Song.ResolveSong(query, musicType).ConfigureAwait(false);
musicPlayer.AddSong(resolvedSong); musicPlayer.AddSong(resolvedSong, queuer.Name);
if (!silent) if (!silent)
{ {
var queuedMessage = await textCh.SendMessage($"🎵`Queued`{resolvedSong.PrettyName} **at** `#{musicPlayer.Playlist.Count}`").ConfigureAwait(false); var queuedMessage = await textCh.SendMessage($"🎵`Queued`{resolvedSong.PrettyName} **at** `#{musicPlayer.Playlist.Count}`").ConfigureAwait(false);