Disable voice features

This commit is contained in:
runebaas 2018-04-04 01:41:37 +02:00
parent 8974d6df7e
commit f4ced55d15
No known key found for this signature in database
GPG key ID: 2677AF508D0300D6

View file

@ -1,102 +1,102 @@
using System; //using System;
using System.IO; //using System.IO;
using System.Threading.Tasks; //using System.Threading.Tasks;
using Discord; //using Discord;
using Discord.Commands; //using Discord.Commands;
using Geekbot.net.Lib; //using Geekbot.net.Lib;
//
namespace Geekbot.net.Commands //namespace Geekbot.net.Commands
{ //{
public class Voice : ModuleBase // public class Voice : ModuleBase
{ // {
private readonly IAudioUtils _audioUtils; // private readonly IAudioUtils _audioUtils;
private readonly IErrorHandler _errorHandler; // private readonly IErrorHandler _errorHandler;
//
public Voice(IErrorHandler errorHandler, IAudioUtils audioUtils) // public Voice(IErrorHandler errorHandler, IAudioUtils audioUtils)
{ // {
_errorHandler = errorHandler; // _errorHandler = errorHandler;
_audioUtils = audioUtils; // _audioUtils = audioUtils;
} // }
//
[Command("join")] // [Command("join")]
public async Task JoinChannel() // public async Task JoinChannel()
{ // {
try // try
{ // {
// Get the audio channel // // Get the audio channel
var channel = (Context.User as IGuildUser)?.VoiceChannel; // var channel = (Context.User as IGuildUser)?.VoiceChannel;
if (channel == null) // if (channel == null)
{ // {
await Context.Channel.SendMessageAsync( // await Context.Channel.SendMessageAsync(
"User must be in a voice channel, or a voice channel must be passed as an argument."); // "User must be in a voice channel, or a voice channel must be passed as an argument.");
return; // return;
} // }
//
// For the next step with transmitting audio, you would want to pass this Audio Client in to a service. // // For the next step with transmitting audio, you would want to pass this Audio Client in to a service.
var audioClient = await channel.ConnectAsync(); // var audioClient = await channel.ConnectAsync();
_audioUtils.StoreAudioClient(Context.Guild.Id, audioClient); // _audioUtils.StoreAudioClient(Context.Guild.Id, audioClient);
await ReplyAsync($"Connected to {channel.Name}"); // await ReplyAsync($"Connected to {channel.Name}");
} // }
catch (Exception e) // catch (Exception e)
{ // {
_errorHandler.HandleCommandException(e, Context); // _errorHandler.HandleCommandException(e, Context);
} // }
} // }
//
[Command("disconnect")] // [Command("disconnect")]
public async Task DisconnectChannel() // public async Task DisconnectChannel()
{ // {
try // try
{ // {
var audioClient = _audioUtils.GetAudioClient(Context.Guild.Id); // var audioClient = _audioUtils.GetAudioClient(Context.Guild.Id);
if (audioClient == null) // if (audioClient == null)
{ // {
await Context.Channel.SendMessageAsync("I'm not in a voice channel at the moment"); // await Context.Channel.SendMessageAsync("I'm not in a voice channel at the moment");
return; // return;
} // }
//
await audioClient.StopAsync(); // await audioClient.StopAsync();
await ReplyAsync("Disconnected from channel!"); // await ReplyAsync("Disconnected from channel!");
_audioUtils.Cleanup(Context.Guild.Id); // _audioUtils.Cleanup(Context.Guild.Id);
} // }
catch (Exception e) // catch (Exception e)
{ // {
_errorHandler.HandleCommandException(e, Context); // _errorHandler.HandleCommandException(e, Context);
_audioUtils.Cleanup(Context.Guild.Id); // _audioUtils.Cleanup(Context.Guild.Id);
} // }
} // }
//
[Command("ytplay")] // [Command("ytplay")]
public async Task ytplay(string url) // public async Task ytplay(string url)
{ // {
try // try
{ // {
if (!url.Contains("youtube")) // if (!url.Contains("youtube"))
{ // {
await ReplyAsync("I can only play youtube videos"); // await ReplyAsync("I can only play youtube videos");
return; // return;
} // }
var audioClient = _audioUtils.GetAudioClient(Context.Guild.Id); // var audioClient = _audioUtils.GetAudioClient(Context.Guild.Id);
if (audioClient == null) // if (audioClient == null)
{ // {
await ReplyAsync("I'm not in a voice channel at the moment"); // await ReplyAsync("I'm not in a voice channel at the moment");
return; // return;
} // }
//
var message = await Context.Channel.SendMessageAsync("Just a second, i'm still a bit slow at this"); // var message = await Context.Channel.SendMessageAsync("Just a second, i'm still a bit slow at this");
var ffmpeg = _audioUtils.CreateStreamFromYoutube(url, Context.Guild.Id); // var ffmpeg = _audioUtils.CreateStreamFromYoutube(url, Context.Guild.Id);
var output = ffmpeg.StandardOutput.BaseStream; // var output = ffmpeg.StandardOutput.BaseStream;
await message.ModifyAsync(msg => msg.Content = "**Playing!** Please note that this feature is experimental"); // await message.ModifyAsync(msg => msg.Content = "**Playing!** Please note that this feature is experimental");
var discord = audioClient.CreatePCMStream(Discord.Audio.AudioApplication.Mixed); // var discord = audioClient.CreatePCMStream(Discord.Audio.AudioApplication.Mixed);
await output.CopyToAsync(discord); // await output.CopyToAsync(discord);
await discord.FlushAsync(); // await discord.FlushAsync();
_audioUtils.Cleanup(Context.Guild.Id); // _audioUtils.Cleanup(Context.Guild.Id);
} // }
catch (Exception e) // catch (Exception e)
{ // {
_errorHandler.HandleCommandException(e, Context); // _errorHandler.HandleCommandException(e, Context);
_audioUtils.Cleanup(Context.Guild.Id); // _audioUtils.Cleanup(Context.Guild.Id);
} // }
} // }
} // }
} //}