repeat
This commit is contained in:
parent
205b71dea7
commit
2862ab0f1b
@ -21,47 +21,55 @@ namespace TextCommandFramework.Modules
|
||||
[Command("play", RunMode = RunMode.Async)]
|
||||
public async Task PlayAsync([Remainder] string text)
|
||||
{
|
||||
var user = Context.User;
|
||||
if (user.IsBot) return;
|
||||
|
||||
Console.WriteLine("Joining on " + Context.Guild.Name);
|
||||
|
||||
string youtubeUrl = text;
|
||||
IVoiceChannel channel = (Context.User as IVoiceState).VoiceChannel;
|
||||
if (channel is null)
|
||||
{
|
||||
await Context.Channel.SendMessageAsync("You need to be in a voice channel to use this command.");
|
||||
return;
|
||||
throw new Exception("You must be connect in a voice channel!");
|
||||
}
|
||||
|
||||
await PlayerService.Play(Context, text);
|
||||
}
|
||||
|
||||
[Command("join", RunMode = RunMode.Async)]
|
||||
public async Task JoinAsync()
|
||||
{
|
||||
Console.WriteLine("Joining on " + Context.Guild.Name);
|
||||
|
||||
IVoiceChannel channel = (Context.User as IVoiceState).VoiceChannel;
|
||||
if (channel is null)
|
||||
{
|
||||
throw new Exception("You must be connect in a voice channel!");
|
||||
}
|
||||
|
||||
await PlayerService.Join(Context);
|
||||
}
|
||||
|
||||
[Command("stop", RunMode = RunMode.Async)]
|
||||
public async Task StopAsync()
|
||||
{
|
||||
var user = Context.User;
|
||||
if (user.IsBot) return;
|
||||
|
||||
await PlayerService.Stop(Context.Guild.Id);
|
||||
}
|
||||
|
||||
[Command("skip", RunMode = RunMode.Async)]
|
||||
public async Task SkipAsync()
|
||||
{
|
||||
var user = Context.User;
|
||||
if (user.IsBot) return;
|
||||
|
||||
await PlayerService.Skip(Context.Guild.Id);
|
||||
}
|
||||
|
||||
[Command("leave", RunMode = RunMode.Async)]
|
||||
public async Task LeaveAsync()
|
||||
{
|
||||
var user = Context.User;
|
||||
if (user.IsBot) return;
|
||||
|
||||
await PlayerService.Leave(Context.Guild.Id);
|
||||
}
|
||||
|
||||
[Alias("r")]
|
||||
[Command("repeat", RunMode = RunMode.Async)]
|
||||
public async Task RepeatAsync()
|
||||
{
|
||||
await PlayerService.Repeat(Context.Guild.Id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ namespace Kasbot.Services
|
||||
return conn;
|
||||
}
|
||||
|
||||
public async Task Play(SocketCommandContext Context, string arguments)
|
||||
public async Task Play(ShardedCommandContext Context, string arguments)
|
||||
{
|
||||
var media = new Media()
|
||||
{
|
||||
@ -60,6 +60,14 @@ namespace Kasbot.Services
|
||||
{
|
||||
var startPlay = conn.Queue.Count == 0;
|
||||
|
||||
if (media.Search.Contains("-r"))
|
||||
{
|
||||
media.Repeat = true;
|
||||
media.Search.Replace("-r", "");
|
||||
}
|
||||
|
||||
media.Search.Trim();
|
||||
|
||||
switch (YoutubeService.GetSearchType(media.Search))
|
||||
{
|
||||
case SearchType.StringSearch:
|
||||
@ -115,7 +123,7 @@ namespace Kasbot.Services
|
||||
return;
|
||||
}
|
||||
|
||||
// since we can't verify if the bot was disconnected by a websocket error, we do this check
|
||||
// since we can't verify if the bot was disconnected by a websocket error, we do this check which should do enough
|
||||
if (Clients[guildId].AudioClient.ConnectionState == ConnectionState.Disconnected)
|
||||
{
|
||||
var voiceChannel = Clients[guildId].AudioChannel;
|
||||
@ -201,7 +209,7 @@ namespace Kasbot.Services
|
||||
|
||||
await nextMedia.PlayMessage.TryDeleteAsync();
|
||||
|
||||
if (Clients[guildId].Queue.Count > 0)
|
||||
if (Clients[guildId].Queue.Count > 0 && !Clients[guildId].Queue.First().Repeat)
|
||||
Clients[guildId].Queue.Dequeue();
|
||||
|
||||
await PlayNext(guildId);
|
||||
@ -229,12 +237,12 @@ namespace Kasbot.Services
|
||||
public Task Skip(ulong guildId)
|
||||
{
|
||||
if (!Clients.ContainsKey(guildId))
|
||||
return Task.CompletedTask;
|
||||
throw new Exception("Bot is not connected!");
|
||||
|
||||
var media = Clients[guildId];
|
||||
|
||||
if (media.CurrentAudioStream == null)
|
||||
return Task.CompletedTask;
|
||||
throw new Exception("There is no audio playing!");
|
||||
|
||||
media.CurrentAudioStream.Close();
|
||||
|
||||
@ -244,7 +252,7 @@ namespace Kasbot.Services
|
||||
public async Task Stop(ulong guildId)
|
||||
{
|
||||
if (!Clients.ContainsKey(guildId))
|
||||
return;
|
||||
throw new Exception("Bot is not connected!");
|
||||
|
||||
var media = Clients[guildId];
|
||||
|
||||
@ -262,7 +270,7 @@ namespace Kasbot.Services
|
||||
public async Task Leave(ulong guildId)
|
||||
{
|
||||
if (!Clients.ContainsKey(guildId))
|
||||
return;
|
||||
throw new Exception("Bot is not connected!");
|
||||
|
||||
await Stop(guildId);
|
||||
var media = Clients[guildId];
|
||||
@ -272,6 +280,28 @@ namespace Kasbot.Services
|
||||
|
||||
Clients.Remove(guildId);
|
||||
}
|
||||
|
||||
public async Task Repeat(ulong guildId)
|
||||
{
|
||||
if (!Clients.ContainsKey(guildId))
|
||||
throw new Exception("Bot is not connected!");
|
||||
|
||||
if (Clients[guildId].Queue.Count == 0)
|
||||
throw new Exception("The queue is empty!");
|
||||
|
||||
var media = Clients[guildId].Queue.First();
|
||||
Clients[guildId].Queue.First().Repeat = !media.Repeat;
|
||||
await media.Channel.SendTemporaryMessageAsync(media.Repeat ? "Repeat turned on!" : "Repeat turned off!");
|
||||
}
|
||||
|
||||
public async Task Join(ShardedCommandContext Context)
|
||||
{
|
||||
var guildId = Context.Guild.Id;
|
||||
if (Clients.ContainsKey(guildId))
|
||||
return;
|
||||
|
||||
await CreateConnection(guildId, (Context.User as IVoiceState).VoiceChannel);
|
||||
}
|
||||
}
|
||||
|
||||
public class Connection
|
||||
|
@ -118,6 +118,7 @@ namespace Kasbot.Services
|
||||
public VideoId? VideoId { get; set; }
|
||||
public RestUserMessage PlayMessage { get; set; }
|
||||
public RestUserMessage? QueueMessage { get; set; }
|
||||
public bool Repeat { get; set; }
|
||||
|
||||
private SocketUserMessage message;
|
||||
public SocketUserMessage Message
|
||||
|
Loading…
x
Reference in New Issue
Block a user