public IHttpActionResult Get(string sound, string user) { var file = _soundRepository.GetSoundFile(sound); if (null == file) { return(BadRequest($"Sound '{sound}' does not exist")); } var server = _bot.FindServers(_options.Server).FirstOrDefault(); if (null == server) { return(BadRequest($"Could not find server '{_options.Server}'")); } var discordUser = server.FindUsers(user).FirstOrDefault(); if (discordUser == null) { return(BadRequest($"Could not find user '{user}'")); } var channel = discordUser.VoiceChannel; if (null == channel) { return(BadRequest("Could not find voice channel")); } _player.PlayAsync(channel, file.Path); return(Ok()); }
private void OnKeyPressed(object sender, ControllerEventArgs args) { var key = args.Key; var state = args.State; if (state != InputEvent.State.Pressed) { return; } var server = _bot.FindServers(_options.Server).FirstOrDefault(); if (null == server) { Logger.Error("Could not find server"); return; } var user = server.FindUsers(_options.User).FirstOrDefault(); if (user == null) { Logger.Error("Could not find user"); return; } var channel = user.VoiceChannel; if (null == channel) { Logger.Error("Could not find voice channel"); return; } var soundName = GetSound(key); if (null == soundName) { Logger.Error("Could not find sound"); return; } var sound = _soundRepository.GetSoundFile(soundName); _player.PlayAsync(channel, sound.Path); }