small changes
This commit is contained in:
parent
d242952d4a
commit
f8ad6dda50
@ -253,10 +253,9 @@ namespace NadekoBot.Modules.Music
|
|||||||
|
|
||||||
[NadekoCommand, Usage, Description, Aliases]
|
[NadekoCommand, Usage, Description, Aliases]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public Task Destroy()
|
public async Task Destroy()
|
||||||
{
|
{
|
||||||
_music.DestroyPlayer(Context.Guild.Id);
|
await _music.DestroyPlayer(Context.Guild.Id);
|
||||||
return Task.CompletedTask;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[NadekoCommand, Usage, Description, Aliases]
|
[NadekoCommand, Usage, Description, Aliases]
|
||||||
|
@ -15,7 +15,7 @@ namespace NadekoBot.Services.Music
|
|||||||
Playing,
|
Playing,
|
||||||
Completed
|
Completed
|
||||||
}
|
}
|
||||||
public class MusicPlayer : IDisposable
|
public class MusicPlayer
|
||||||
{
|
{
|
||||||
private readonly Task _player;
|
private readonly Task _player;
|
||||||
private readonly IVoiceChannel VoiceChannel;
|
private readonly IVoiceChannel VoiceChannel;
|
||||||
@ -92,7 +92,12 @@ namespace NadekoBot.Services.Music
|
|||||||
});
|
});
|
||||||
var ac = await GetAudioClient();
|
var ac = await GetAudioClient();
|
||||||
if (ac == null)
|
if (ac == null)
|
||||||
|
{
|
||||||
|
await Task.Delay(900);
|
||||||
|
// just wait some time, maybe bot doesn't even have perms to join that voice channel,
|
||||||
|
// i don't want to spam connection attempts
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
var pcm = ac.CreatePCMStream(AudioApplication.Music);
|
var pcm = ac.CreatePCMStream(AudioApplication.Music);
|
||||||
|
|
||||||
OnStarted?.Invoke(this, data.Song);
|
OnStarted?.Invoke(this, data.Song);
|
||||||
@ -175,9 +180,9 @@ namespace NadekoBot.Services.Music
|
|||||||
{
|
{
|
||||||
Stopped = false;
|
Stopped = false;
|
||||||
Unpause();
|
Unpause();
|
||||||
}
|
|
||||||
CancelCurrentSong();
|
CancelCurrentSong();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void Stop(bool clearQueue = false)
|
public void Stop(bool clearQueue = false)
|
||||||
{
|
{
|
||||||
@ -188,9 +193,9 @@ namespace NadekoBot.Services.Music
|
|||||||
if (clearQueue)
|
if (clearQueue)
|
||||||
Queue.Clear();
|
Queue.Clear();
|
||||||
Unpause();
|
Unpause();
|
||||||
}
|
|
||||||
CancelCurrentSong();
|
CancelCurrentSong();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void Unpause()
|
private void Unpause()
|
||||||
{
|
{
|
||||||
@ -283,19 +288,23 @@ namespace NadekoBot.Services.Music
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Dispose()
|
public async Task Destroy()
|
||||||
{
|
{
|
||||||
_log.Info("Disposing");
|
_log.Info("Destroying");
|
||||||
lock (locker)
|
lock (locker)
|
||||||
{
|
{
|
||||||
|
Stop();
|
||||||
Exited = true;
|
Exited = true;
|
||||||
Unpause();
|
Unpause();
|
||||||
}
|
|
||||||
CancelCurrentSong();
|
|
||||||
OnCompleted = null;
|
OnCompleted = null;
|
||||||
OnPauseChanged = null;
|
OnPauseChanged = null;
|
||||||
OnStarted = null;
|
OnStarted = null;
|
||||||
}
|
}
|
||||||
|
var ac = _audioClient;
|
||||||
|
if (ac != null)
|
||||||
|
await ac.StopAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//private IAudioClient AudioClient { get; set; }
|
//private IAudioClient AudioClient { get; set; }
|
||||||
|
@ -112,8 +112,11 @@ namespace NadekoBot.Services.Music
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void ResetCurrent()
|
public void ResetCurrent()
|
||||||
|
{
|
||||||
|
lock (locker)
|
||||||
{
|
{
|
||||||
CurrentIndex = 0;
|
CurrentIndex = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
@ -5,11 +5,9 @@ using System.Threading.Tasks;
|
|||||||
using Discord;
|
using Discord;
|
||||||
using NadekoBot.Extensions;
|
using NadekoBot.Extensions;
|
||||||
using NadekoBot.Services.Database.Models;
|
using NadekoBot.Services.Database.Models;
|
||||||
using System.Text.RegularExpressions;
|
|
||||||
using NLog;
|
using NLog;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using VideoLibrary;
|
using VideoLibrary;
|
||||||
using System.Net.Http;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Discord.Commands;
|
using Discord.Commands;
|
||||||
|
|
||||||
@ -235,10 +233,10 @@ namespace NadekoBot.Services.Music
|
|||||||
return song;
|
return song;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DestroyPlayer(ulong id)
|
public async Task DestroyPlayer(ulong id)
|
||||||
{
|
{
|
||||||
if (MusicPlayers.TryRemove(id, out var mp))
|
if (MusicPlayers.TryRemove(id, out var mp))
|
||||||
mp.Dispose();
|
await mp.Destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
// public async Task QueueSong(IGuildUser queuer, ITextChannel textCh, IVoiceChannel voiceCh, string query, bool silent = false, MusicType musicType = MusicType.Normal)
|
// public async Task QueueSong(IGuildUser queuer, ITextChannel textCh, IVoiceChannel voiceCh, string query, bool silent = false, MusicType musicType = MusicType.Normal)
|
||||||
|
Loading…
Reference in New Issue
Block a user