More music stuff, more fixes

This commit is contained in:
Kwoth 2016-12-22 05:32:34 +01:00
parent 727da69c81
commit 0b1d47fc4e
10 changed files with 60 additions and 80 deletions

View File

@ -195,12 +195,8 @@ namespace NadekoBot.Modules.Administration
if (conf.AutoDeleteSelfAssignedRoleMessages)
{
var t = Task.Run(async () =>
{
await Task.Delay(3000).ConfigureAwait(false);
try { await msg.DeleteAsync().ConfigureAwait(false); } catch { } // if 502 or something, i don't want bot crashing
try { await usrMsg.DeleteAsync().ConfigureAwait(false); } catch { }
});
msg.DeleteAfter(3);
umsg.DeleteAfter(3);
}
}
@ -242,12 +238,8 @@ namespace NadekoBot.Modules.Administration
if (autoDeleteSelfAssignedRoleMessages)
{
var t = Task.Run(async () =>
{
await Task.Delay(3000).ConfigureAwait(false);
try { await msg.DeleteAsync().ConfigureAwait(false); } catch { } // if 502 or something, i don't want bot crashing
try { await umsg.DeleteAsync().ConfigureAwait(false); } catch { }
});
msg.DeleteAfter(3);
umsg.DeleteAfter(3);
}
}
}

View File

@ -52,11 +52,7 @@ namespace NadekoBot.Modules.Administration
var toDelete = await channel.SendMessageAsync(msg.SanitizeMentions()).ConfigureAwait(false);
if (conf.AutoDeleteByeMessagesTimer > 0)
{
var t = Task.Run(async () =>
{
await Task.Delay(conf.AutoDeleteByeMessagesTimer * 1000).ConfigureAwait(false); // 5 minutes
try { await toDelete.DeleteAsync().ConfigureAwait(false); } catch { }
});
toDelete.DeleteAfter(conf.AutoDeleteByeMessagesTimer);
}
}
catch (Exception ex) { _log.Warn(ex); }
@ -91,11 +87,7 @@ namespace NadekoBot.Modules.Administration
var toDelete = await channel.SendMessageAsync(msg.SanitizeMentions()).ConfigureAwait(false);
if (conf.AutoDeleteGreetMessagesTimer > 0)
{
var t = Task.Run(async () =>
{
await Task.Delay(conf.AutoDeleteGreetMessagesTimer * 1000).ConfigureAwait(false); // 5 minutes
try { await toDelete.DeleteAsync().ConfigureAwait(false); } catch { }
});
toDelete.DeleteAfter(conf.AutoDeleteGreetMessagesTimer);
}
}
catch (Exception ex) { _log.Warn(ex); }

View File

@ -118,7 +118,7 @@ namespace NadekoBot.Modules.Games.Commands.Hangman
.AddField(efb => efb.WithName("It was").WithValue(Term.Word))
.WithImage(eib => eib.WithUrl(Term.ImageUrl));
if (Errors >= MaxErrors)
await GameChannel.EmbedAsync(embed.WithColor(NadekoBot.ErrorColor).Build()).ConfigureAwait(false);
await GameChannel.EmbedAsync(embed.WithErrorColor().Build()).ConfigureAwait(false);
else
await GameChannel.EmbedAsync(embed.WithOkColor().Build()).ConfigureAwait(false);
}

View File

@ -119,11 +119,7 @@ namespace NadekoBot.Modules.Games
await CurrencyHandler.AddCurrencyAsync((IGuildUser)imsg.Author, "Picked flower(s).", msgs.Count, false).ConfigureAwait(false);
var msg = await channel.SendConfirmAsync($"**{imsg.Author}** picked {msgs.Count}{Gambling.Gambling.CurrencySign}!").ConfigureAwait(false);
var t = Task.Run(async () =>
{
await Task.Delay(10000).ConfigureAwait(false);
try { await msg.DeleteAsync().ConfigureAwait(false); } catch (Exception ex) { _log.Warn(ex); }
});
msg.DeleteAfter(10);
}
[NadekoCommand, Usage, Description, Aliases]

View File

@ -172,8 +172,7 @@ namespace NadekoBot.Modules.Games
else
{
var toDelete = await ch.SendConfirmAsync($"{msg.Author.Mention} cast their vote.").ConfigureAwait(false);
await Task.Delay(5000);
await toDelete.DeleteAsync().ConfigureAwait(false);
toDelete.DeleteAfter(5);
}
}
}

View File

@ -41,9 +41,9 @@ namespace NadekoBot.Modules.Music.Classes
public float Volume { get; private set; }
public event Func<MusicPlayer, Song, Task> OnCompleted = delegate { return Task.CompletedTask; };
public event Func<MusicPlayer, Song, Task> OnStarted = delegate { return Task.CompletedTask; };
public event Func<bool, Task> OnPauseChanged = delegate { return Task.CompletedTask; };
public event Action<MusicPlayer, Song> OnCompleted = delegate { };
public event Action<MusicPlayer, Song> OnStarted = delegate { };
public event Action<bool> OnPauseChanged = delegate { };
public IVoiceChannel PlaybackVoiceChannel { get; private set; }

View File

@ -31,7 +31,7 @@ namespace NadekoBot.Modules.Music.Classes
public string QueuerName { get; set; }
public TimeSpan TotalTime { get; set; } = TimeSpan.Zero;
public TimeSpan CurrentTime => TimeSpan.FromSeconds(bytesSent / frameBytes / 1000 / milliseconds);
public TimeSpan CurrentTime => TimeSpan.FromSeconds(bytesSent / frameBytes / (1000 / milliseconds));
const int milliseconds = 20;
const int samplesPerFrame = (48000 / 1000) * milliseconds;
@ -52,7 +52,7 @@ namespace NadekoBot.Modules.Music.Classes
public string PrettyFullName => $"{PrettyName}\n\t\t*{PrettyInfo}*";
public string PrettyCurrentTime => TotalTime.ToString(@"mm\:ss");
public string PrettyCurrentTime => CurrentTime.ToString(@"mm\:ss");
private string PrettyTotalTime {
get {

View File

@ -15,6 +15,7 @@ using Newtonsoft.Json.Linq;
using System.Collections.Generic;
using NadekoBot.Services.Database.Models;
using System.Text.RegularExpressions;
using System.Threading;
namespace NadekoBot.Modules.Music
{
@ -99,7 +100,6 @@ namespace NadekoBot.Modules.Music
[NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)]
public async Task Destroy(IUserMessage umsg)
//public Task Destroy(IUserMessage umsg)
{
var channel = (ITextChannel)umsg.Channel;
await channel.SendErrorAsync("This command is temporarily disabled.").ConfigureAwait(false);
@ -135,8 +135,7 @@ namespace NadekoBot.Modules.Music
await QueueSong(((IGuildUser)umsg.Author), channel, ((IGuildUser)umsg.Author).VoiceChannel, query).ConfigureAwait(false);
if (channel.Guild.GetCurrentUser().GetPermissions(channel).ManageMessages)
{
await Task.Delay(10000).ConfigureAwait(false);
await ((IUserMessage)umsg).DeleteAsync().ConfigureAwait(false);
umsg.DeleteAfter(10);
}
}
@ -149,8 +148,7 @@ namespace NadekoBot.Modules.Music
await QueueSong(((IGuildUser)umsg.Author), channel, ((IGuildUser)umsg.Author).VoiceChannel, query, musicType: MusicType.Soundcloud).ConfigureAwait(false);
if (channel.Guild.GetCurrentUser().GetPermissions(channel).ManageMessages)
{
await Task.Delay(10000).ConfigureAwait(false);
await ((IUserMessage)umsg).DeleteAsync().ConfigureAwait(false);
umsg.DeleteAfter(10);
}
}
@ -182,7 +180,7 @@ namespace NadekoBot.Modules.Music
var number = 0 + startAt;
var embed = new EmbedBuilder()
.WithAuthor(eab => eab.WithName($"Player Queue: Page {page}")
.WithAuthor(eab => eab.WithName($"Player Queue - Page {page}")
.WithMusicIcon())
.WithDescription(string.Join("\n", musicPlayer.Playlist
.Skip(startAt)
@ -315,17 +313,21 @@ namespace NadekoBot.Modules.Music
var msg =
await channel.SendMessageAsync($"🎵 Attempting to queue **{count}** songs".SnPl(count) + "...").ConfigureAwait(false);
var cancelSource = new CancellationTokenSource();
foreach (var id in idArray)
var tasks = Task.WhenAll(idArray.Select(async id =>
{
if (cancelSource.Token.IsCancellationRequested)
return;
try
{
await QueueSong(((IGuildUser)umsg.Author), channel, ((IGuildUser)umsg.Author).VoiceChannel, id, true).ConfigureAwait(false);
}
catch (SongNotFoundException) { }
catch { break; }
catch { try { cancelSource.Cancel(); } catch { } }
}));
}
await Task.WhenAny(tasks, Task.Delay(Timeout.Infinite, cancelSource.Token));
await msg.ModifyAsync(m => m.Content = "✅ Playlist queue complete.").ConfigureAwait(false);
}
@ -411,8 +413,7 @@ namespace NadekoBot.Modules.Music
await QueueSong(((IGuildUser)umsg.Author), channel, ((IGuildUser)umsg.Author).VoiceChannel, radio_link, musicType: MusicType.Radio).ConfigureAwait(false);
if (channel.Guild.GetCurrentUser().GetPermissions(channel).ManageMessages)
{
await Task.Delay(10000).ConfigureAwait(false);
await ((IUserMessage)umsg).DeleteAsync().ConfigureAwait(false);
umsg.DeleteAfter(10);
}
}
@ -459,12 +460,13 @@ namespace NadekoBot.Modules.Music
return;
var song = (musicPlayer.Playlist as List<Song>)?[num - 1];
musicPlayer.RemoveSongAt(num - 1);
//await channel.SendConfirmAsync($"🎵 Track {song.PrettyName} at position `#{num}` has been **removed**.").ConfigureAwait(false);
var embed = new EmbedBuilder()
.WithAuthor(eab => eab.WithName("Song Removed!").WithMusicIcon())
.AddField(fb => fb.WithName("**Song Position**").WithValue($"#{num}").WithIsInline(true))
.AddField(fb => fb.WithName("**Song Name**").WithValue($"**[{song.SongInfo.Title.TrimTo(70)}]({song.SongInfo.Query})** `{song.PrettyProvider} | {song.QueuerName.TrimTo(15)}`").WithIsInline(true))
.WithColor(NadekoBot.ErrorColor);
.WithErrorColor();
await channel.EmbedAsync(embed.Build()).ConfigureAwait(false);
}
@ -661,10 +663,6 @@ namespace NadekoBot.Modules.Music
playlists = uow.MusicPlaylists.GetPlaylistsOnPage(num);
}
//await channel.SendConfirmAsync($@"🎶 **Page {num} of saved playlists:**
//" + string.Join("\n", playlists.Select(r => $"`#{r.Id}` - **{r.Name}** by __{r.Author}__ ({r.Songs.Count} songs)"))).ConfigureAwait(false);
var embed = new EmbedBuilder()
.WithAuthor(eab => eab.WithName($"Page {num} of Saved Playlists").WithMusicIcon())
.WithDescription(string.Join("\n", playlists.Select(r => $"`#{r.Id}` - **{r.Name}**\t by **`{r.Author}`**\t ({r.Songs.Count} songs)")))
@ -843,30 +841,38 @@ namespace NadekoBot.Modules.Music
IUserMessage playingMessage = null;
mp.OnStarted += async (player, song) =>
{
if (playingMessage != null)
playingMessage.DeleteAfter(0);
try
{
if (playingMessage != null)
playingMessage.DeleteAfter(0);
playingMessage = await textCh.EmbedAsync(new EmbedBuilder().WithOkColor()
.WithAuthor(eab => eab.WithName("Playing Song").WithMusicIcon())
.WithDescription(song.PrettyName)
.WithFooter(ef => ef.WithText(song.PrettyInfo))
.Build())
.ConfigureAwait(false);
playingMessage = await textCh.EmbedAsync(new EmbedBuilder().WithOkColor()
.WithAuthor(eab => eab.WithName("Playing Song").WithMusicIcon())
.WithDescription(song.PrettyName)
.WithFooter(ef => ef.WithText(song.PrettyInfo))
.Build())
.ConfigureAwait(false);
}
catch { }
};
mp.OnPauseChanged += async (paused) =>
{
IUserMessage pauseMessage = null;
if (paused)
try
{
pauseMessage = await textCh.SendConfirmAsync("🎵 Music playback **paused**.").ConfigureAwait(false);
IUserMessage pauseMessage = null;
if (paused)
{
pauseMessage = await textCh.SendConfirmAsync("🎵 Music playback **paused**.").ConfigureAwait(false);
}
else
{
pauseMessage = await textCh.SendConfirmAsync("🎵 Music playback **resumed**.").ConfigureAwait(false);
}
if (pauseMessage != null)
pauseMessage.DeleteAfter(15);
}
else
{
pauseMessage = await textCh.SendConfirmAsync("🎵 Music playback **resumed**.").ConfigureAwait(false);
}
if (pauseMessage != null)
pauseMessage.DeleteAfter(15);
catch { }
};
return mp;
});
@ -898,16 +904,8 @@ namespace NadekoBot.Modules.Music
.WithFooter(ef => ef.WithText($"{resolvedSong.PrettyProvider}"))
.Build())
.ConfigureAwait(false);
var t = Task.Run(async () =>
{
try
{
await Task.Delay(10000).ConfigureAwait(false);
await queuedMessage.DeleteAsync().ConfigureAwait(false);
}
catch { }
}).ConfigureAwait(false);
if (queuedMessage != null)
queuedMessage.DeleteAfter(10);
}
catch { } // if queued message sending fails, don't attempt to delete it
}

View File

@ -247,7 +247,7 @@ namespace NadekoBot.Modules.NSFW
if (matches.Count == 0)
return null;
return matches[rng.Next(0, matches.Count)].Groups["ll"].Value;
return "http:" + matches[rng.Next(0, matches.Count)].Groups["ll"].Value;
}
}

View File

@ -28,6 +28,9 @@ namespace NadekoBot.Extensions
public static EmbedBuilder WithOkColor(this EmbedBuilder eb) =>
eb.WithColor(NadekoBot.OkColor);
public static EmbedBuilder WithErrorColor(this EmbedBuilder eb) =>
eb.WithColor(NadekoBot.ErrorColor);
public static IMessage DeleteAfter(this IUserMessage msg, int seconds)
{
Task.Run(async () =>