!changelog command, slightly improved info command, foundation for voice features
This commit is contained in:
parent
12919acf95
commit
b45370cf9e
5 changed files with 219 additions and 4 deletions
85
Geekbot.net/Commands/Voice.cs
Normal file
85
Geekbot.net/Commands/Voice.cs
Normal file
|
@ -0,0 +1,85 @@
|
|||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Discord;
|
||||
using Discord.Audio;
|
||||
using Discord.Commands;
|
||||
using Geekbot.net.Lib;
|
||||
|
||||
namespace Geekbot.net.Commands
|
||||
{
|
||||
public class Voice : ModuleBase
|
||||
{
|
||||
private readonly IErrorHandler _errorHandler;
|
||||
private readonly IAudioUtils _audioUtils;
|
||||
|
||||
public Voice(IErrorHandler errorHandler, IAudioUtils audioUtils)
|
||||
{
|
||||
_errorHandler = errorHandler;
|
||||
_audioUtils = audioUtils;
|
||||
}
|
||||
|
||||
[Command("join")]
|
||||
public async Task JoinChannel()
|
||||
{
|
||||
try
|
||||
{
|
||||
// Get the audio channel
|
||||
var channel = (Context.User as IGuildUser)?.VoiceChannel;
|
||||
if (channel == null)
|
||||
{
|
||||
await Context.Channel.SendMessageAsync(
|
||||
"User must be in a voice channel, or a voice channel must be passed as an argument.");
|
||||
return;
|
||||
}
|
||||
|
||||
// For the next step with transmitting audio, you would want to pass this Audio Client in to a service.
|
||||
var audioClient = await channel.ConnectAsync();
|
||||
_audioUtils.StoreAudioClient(Context.Guild.Id, audioClient);
|
||||
await ReplyAsync($"Connected to {channel.Name}");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_errorHandler.HandleCommandException(e, Context);
|
||||
}
|
||||
}
|
||||
|
||||
[Command("disconnect")]
|
||||
public async Task DisconnectChannel()
|
||||
{
|
||||
try
|
||||
{
|
||||
var audioClient = _audioUtils.GetAudioClient(Context.Guild.Id);
|
||||
if (audioClient == null)
|
||||
{
|
||||
await Context.Channel.SendMessageAsync("I'm not in a voice channel at the moment");
|
||||
return;
|
||||
}
|
||||
await audioClient.StopAsync();
|
||||
await ReplyAsync("Disconnected from channel!");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_errorHandler.HandleCommandException(e, Context);
|
||||
}
|
||||
}
|
||||
|
||||
// [Command("play")]
|
||||
// public async Task play(IVoiceChannel channel = null)
|
||||
// {
|
||||
// try
|
||||
// {
|
||||
// var audioClient = _audioUtils.GetAudioClient(Context.Guild.Id);
|
||||
// if (audioClient == null)
|
||||
// {
|
||||
// await Context.Channel.SendMessageAsync("I'm not in a voice channel at the moment");
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// }
|
||||
// catch (Exception e)
|
||||
// {
|
||||
// _errorHandler.HandleCommandException(e, Context);
|
||||
// }
|
||||
// }
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue