stuff
This commit is contained in:
parent
9cab284d24
commit
4060c72ac1
@ -24,6 +24,8 @@ namespace TextCommandFramework.Modules
|
|||||||
var user = Context.User;
|
var user = Context.User;
|
||||||
if (user.IsBot) return;
|
if (user.IsBot) return;
|
||||||
|
|
||||||
|
Console.WriteLine("Joining on " + Context.Guild.Name);
|
||||||
|
|
||||||
string youtubeUrl = text;
|
string youtubeUrl = text;
|
||||||
IVoiceChannel channel = (Context.User as IVoiceState).VoiceChannel;
|
IVoiceChannel channel = (Context.User as IVoiceState).VoiceChannel;
|
||||||
if (channel is null)
|
if (channel is null)
|
||||||
|
@ -18,21 +18,21 @@ namespace Kasbot.Services
|
|||||||
Clients = new Dictionary<ulong, Connection>();
|
Clients = new Dictionary<ulong, Connection>();
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<Connection> CreateConnection(SocketCommandContext Context)
|
private async Task<Connection> CreateConnection(ulong guildId, IVoiceChannel voiceChannel)
|
||||||
{
|
{
|
||||||
IVoiceChannel channel = (Context.User as IVoiceState).VoiceChannel;
|
|
||||||
var conn = new Connection();
|
var conn = new Connection();
|
||||||
IAudioClient audioClient = await channel.ConnectAsync();
|
IAudioClient audioClient = await voiceChannel.ConnectAsync(selfDeaf: true);
|
||||||
|
|
||||||
audioClient.Disconnected += (ex) => Stop(Context.Guild.Id);
|
audioClient.Disconnected += (ex) => Stop(guildId);
|
||||||
audioClient.StreamDestroyed += (ex) => Stop(Context.Guild.Id);
|
audioClient.StreamDestroyed += (ex) => Stop(guildId);
|
||||||
|
|
||||||
conn.AudioClient = audioClient;
|
conn.AudioClient = audioClient;
|
||||||
|
conn.AudioChannel = voiceChannel;
|
||||||
|
|
||||||
if (Clients.ContainsKey(Context.Guild.Id))
|
if (Clients.ContainsKey(guildId))
|
||||||
Clients.Remove(Context.Guild.Id);
|
Clients.Remove(guildId);
|
||||||
|
|
||||||
Clients.Add(Context.Guild.Id, conn);
|
Clients.Add(guildId, conn);
|
||||||
|
|
||||||
return conn;
|
return conn;
|
||||||
}
|
}
|
||||||
@ -52,7 +52,7 @@ namespace Kasbot.Services
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
conn = await CreateConnection(Context);
|
conn = await CreateConnection(Context.Guild.Id, (Context.User as IVoiceState).VoiceChannel);
|
||||||
await Enqueue(Context.Guild.Id, conn, media);
|
await Enqueue(Context.Guild.Id, conn, media);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -115,6 +115,14 @@ namespace Kasbot.Services
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// since we can't verify if the bot was disconnected by a websocket error, we do this check
|
||||||
|
if (Clients[guildId].AudioClient.ConnectionState == ConnectionState.Disconnected)
|
||||||
|
{
|
||||||
|
var voiceChannel = Clients[guildId].AudioChannel;
|
||||||
|
Clients.Remove(guildId);
|
||||||
|
await CreateConnection(guildId, voiceChannel);
|
||||||
|
}
|
||||||
|
|
||||||
var mp3Stream = await YoutubeService.DownloadAudioFromYoutube(nextMedia);
|
var mp3Stream = await YoutubeService.DownloadAudioFromYoutube(nextMedia);
|
||||||
|
|
||||||
if (mp3Stream == null)
|
if (mp3Stream == null)
|
||||||
@ -183,7 +191,7 @@ namespace Kasbot.Services
|
|||||||
});
|
});
|
||||||
await stdout.ContinueWith(async ac =>
|
await stdout.ContinueWith(async ac =>
|
||||||
{
|
{
|
||||||
if (ac.Exception!= null)
|
if (ac.Exception != null)
|
||||||
{
|
{
|
||||||
await nextMedia.Channel.SendTemporaryMessageAsync("Error while playing: " + ac.Exception.ToString());
|
await nextMedia.Channel.SendTemporaryMessageAsync("Error while playing: " + ac.Exception.ToString());
|
||||||
}
|
}
|
||||||
@ -271,6 +279,7 @@ namespace Kasbot.Services
|
|||||||
public class Connection
|
public class Connection
|
||||||
{
|
{
|
||||||
public IAudioClient AudioClient { get; set; }
|
public IAudioClient AudioClient { get; set; }
|
||||||
|
public IVoiceChannel AudioChannel { get; set; }
|
||||||
public Stream? CurrentAudioStream { get; set; }
|
public Stream? CurrentAudioStream { get; set; }
|
||||||
public Queue<Media> Queue { get; set; } = new Queue<Media>();
|
public Queue<Media> Queue { get; set; } = new Queue<Media>();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user